[英]How can I have multiple entry points in a package.json?
I want to be able to run different commands with npm:我希望能够使用 npm 运行不同的命令:
"scripts": {
"v1": "node v1.js",
"v2": "node v2.js"
}
with something like npm start v1
or npm start v2
, but these commands do not run the correct Node command.使用
npm start v1
或npm start v2
之类的命令,但这些命令不会运行正确的 Node 命令。
The alternative would be to have a wrapper index.js or similar which runs the correct version based off the argument supplied to npm start
另一种方法是使用一个包装器 index.js 或类似的包装器,它根据提供给 npm start 的参数运行正确的版本
You can access an array of arguments using process.argv
, and those values should be available whether you use npm start
or node./index.js
您可以使用
process.argv
访问参数数组,无论您使用npm start
还是node./index.js
,这些值都应该可用
Use npm run
:使用
npm run
:
npm run v1
or要么
npm run v2
To add extra parameters add --
:要添加额外参数,请添加
--
:
npm run v1 -- -param_one 1 --param2 2
Which is the equivalent of:这相当于:
node v1.js -param_one 1 --param2 2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.