[英]How to pass command-line variable in package.json script, in NPM?
Pass command line args to npm scripts in package.json is almost what I'm looking for. 将命令行参数传递给 package.json 中的 npm 脚本几乎就是我要找的。
I use Gulp to do our NPM builds.我使用 Gulp 进行 NPM 构建。 I am able to do this, using the yargs plugin
我能够做到这一点,使用yargs 插件
$ gulp build --gitTag 1.0.0
and it produces dist/packageName-1.0.0.zip
file.它产生
dist/packageName-1.0.0.zip
文件。 However, I need to be able to do this但是,我需要能够做到这一点
$ npm run build --gitTag=1.0.0
I tried this,我试过这个,
"scripts": {
"build": "npm ci && gulp build --gitTag %npm_config_gitTag%"
}
...and this ...和这个
"scripts": {
"build": "export GIT_TAG=%npm_config_gitTag% && npm ci && gulp build"
}
However, the %npm_config_gitTag%
is not substituted with my passed-in gitTag
argument, meaning the resulting artifact is packageName-%npm_config_gitTag%.zip
但是,
%npm_config_gitTag%
没有被我传入的gitTag
参数替换,这意味着生成的工件是packageName-%npm_config_gitTag%.zip
What should my build
script look like in my package.json
file?我的
package.json
文件中的build
脚本应该是什么样子?
I found the magic recipe我找到了神奇的食谱
I simply have this in my package.json
我只是在我的
package.json
"scripts": {
"build": "npm ci && gulp build"
}
and use the following command line并使用以下命令行
$ npm run build -- --gitTag 1.0.0
and get the wanted packageName-1.0.0.zip
artifact.并获得想要的
packageName-1.0.0.zip
工件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.