我怎样才能在 package.json 中有多个入口点?
How can I have multiple entry points in a package.json?
我希望能够使用 npm 运行 不同的命令:
"scripts": {
"v1": "node v1.js",
"v2": "node v2.js"
}
使用 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
您可以使用 process.argv
访问参数数组,无论您使用 npm start
还是 node ./index.js
,这些值都应该可用
使用npm run
:
npm run v1
或
npm run v2
要添加额外参数,请添加 --
:
npm run v1 -- -param_one 1 --param2 2
相当于:
node v1.js -param_one 1 --param2 2
我希望能够使用 npm 运行 不同的命令:
"scripts": {
"v1": "node v1.js",
"v2": "node v2.js"
}
使用 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
您可以使用 process.argv
访问参数数组,无论您使用 npm start
还是 node ./index.js
使用npm run
:
npm run v1
或
npm run v2
要添加额外参数,请添加 --
:
npm run v1 -- -param_one 1 --param2 2
相当于:
node v1.js -param_one 1 --param2 2