javascript - 有没有一种优雅的方式将 npm run 选项传递给 grunt 选项

标签 javascript node.js gruntjs

我有一个如下所示的 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/

相关文章:

javascript - 在服务器不知道正在查询的记录的情况下查询服务器是否存在记录

javascript - 使用 grunt 任务更改恒定 Angular 内容

javascript - 有没有办法在不使用 webpack 的情况下使用 grunt 的 es6 导入和导出功能

javascript - grunt-serve 不提供带有 '/' 请求的 index.html

javascript - 如何根据 Javascript 中的 "class"选择器检索 onclick 事件的 href 值?

javascript - 这个图表叫什么?如何在网络浏览器中重现它?

javascript - Semver 太难了还是怎么回事?

json - 如何将json数据追加到文件中?

javascript - 尝试在 angular2 中使用 stomp.js

Node.js 只有一个客户端正在接收消息