简体   繁体   English

将参数从cmd行传递到package.json

[英]Passing a param from cmd line to package.json

"scripts": {
    "start": "gulp",
    ...
  },

I'm using a package that runs via npm start. 我正在使用通过npm start运行的软件包。 I want to pass params to the start command. 我想将参数传递给start命令。

How can I pass the param in the command line? 如何在命令行中传递参数?

npm start --myparam = hello

Alos, how can I access this in my package.jspn file to pass through to gulp: Alos,我该如何在package.jspn文件中访问此文件以传递到gulp:

"scripts": {
    "start": "gulp --myparam",
    ...
  },

If I understand your question correctly, you are trying to run gulp --myparam=hello with the npm start command. 如果我正确理解了您的问题,则您正在尝试使用npm start命令运行gulp --myparam=hello

The correct way to do this is npm start -- --myparam=hello . 正确的方法是npm start -- --myparam=hello

Notice the -- in the command. 注意命令中的-- Anything after the -- will be passed directly to the start command ( gulp ). --之后的所有内容都将直接传递给启动命令( gulp )。

The reason for requiring the -- is that npm start (and npm run ) can take parameters as well; 要求--的原因是npm start (和npm run )也可以采用参数。 like -s to silence the default output from npm . like -s使npm的默认输出静音。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM