问题描述
我开发了一个托管在 npmjs 上的小型 angular 包.当我尝试安装我的软件包时,我想更改我的选择器"名称,以便我编写了一个如下所示的 gulp 任务:
gulp.task('tag-change', function () {//var files = fs.readFileSync('./node_modules/@syncfusion/ej2-angular-buttons/@syncfusion/ej2-angular-buttons.es5.js', 'utf8');var files = glob.sync('./dist/@syncfusion/*');for (var i = 0; i
我想在我的包安装后运行这个任务.为此,我分析并发现我们可以使用
我从这个问题中引用了这个 gulp 任务参考 -
最后,我找到了一个解决方案来满足我的要求.
我创建了一个 tagchange.js
文件并放置了以下内容.
var fs = require('fs');var glob = require('glob');var files = glob.sync('./@syncfusion/*');for (var i = 0; i
我在我的包 package.json
文件中调用了这个,如下所示:
依赖项":{安装后":*"},脚本":{"postinstall": "节点 ./tagchange.js","packagr": "ng-packagr -p ng-package.json && gulp npmrc-changelog-schematics-injection && gulp path-change"}
一切正常
I've developed a small angular package that is hosted on npmjs. when I try to install my package I want to change my "selector" name so that I have written one gulp task like below:
gulp.task('tag-change', function () {
// var files = fs.readFileSync('./node_modules/@syncfusion/ej2-angular-buttons/@syncfusion/ej2-angular-buttons.es5.js', 'utf8');
var files = glob.sync('./dist/@syncfusion/*');
for (var i = 0; i < files.length; i++) {
var sourceFile = fs.readFileSync(files[i],'utf8');
sourceFile = sourceFile.replace(`selector: '[ejs-button]'`,`selector: '[KD-button]'`);
fs.writeFileSync(files[i], sourceFile, 'utf8');
}
});
I want to run this task after my package got installed. for this, I have analyzed and found that we can able to use npm postinstall.
Then i have tried like below:
"dependencies": {
"postinstall": "*"
},
"scripts": {
"postinstall": "gulp tag-change",
"packagr": "ng-packagr -p ng-package.json && gulp npmrc-changelog-schematics-injection && gulp path-change"
}
But it throws below error:
I have referred this gulp task reference from this issue - Run gulp task after NPM package install
my package structure lokks like below:
Finally, I found out a solution to achieve my requirements.
I have created a tagchange.js
file and placed the below content.
var fs = require('fs');
var glob = require('glob');
var files = glob.sync('./@syncfusion/*');
for (var i = 0; i < files.length; i++) {
var sourceFile = fs.readFileSync(files[i],'utf8');
sourceFile = sourceFile.replace(`selector: '[ejs-button]'`,`selector: '[Kumar-button]'`);
fs.writeFileSync(files[i], sourceFile, 'utf8');
}
And I have called this in my package package.json
file like below:
"dependencies": {
"postinstall": "*"
},
"scripts": {
"postinstall": "node ./tagchange.js",
"packagr": "ng-packagr -p ng-package.json && gulp npmrc-changelog-schematics-injection && gulp path-change"
}
It is working fine
这篇关于在 NPM 包安装后运行 gulp 任务,无需任何命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!