我有一个如下所示的 package.json,
{
"scripts": {
"start": "node app.js",
"test": "./node_modules/.bin/grunt test"
}
}
我想通过 npm run test
调用测试脚本,参数如下:
npm run test --host=<value1> --testType=<value2>
有没有办法通过 grunt 文件中的 grunt.option
将这些参数读取为 grunt 选项?
如果我像这样传递这些参数:
"test": "./node_modules/.bin/grunt test --host=<value1> --testType=<value2>"
但是根据 testType
,测试运行的性质会有所不同 - 所以如果可以从 npm run
中读取这些值就更好了。
最佳答案
不确定 this是你所追求的,但是:
As of
npm@2.0.0
, you can use custom arguments when executing scripts. The special option--
is used by getopt to delimit the end of the options. npm will pass all the arguments after the--
directly to your script
关于javascript - 有没有一种优雅的方式将 npm run 选项传递给 grunt 选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52746562/