3 回答
TA贡献1829条经验 获得超4个赞
npm run
npm run <command> [-- <args>]
--
npm
package.json
"scripts": { "grunt": "grunt", "server": "node server.js"}
grunt task:target
=> npm run grunt -- task:target
node server.js --port=1337
=> npm run server -- --port=1337
process.argv
原文:
package.json
myPackage
"scripts": { "start": "node ./script.js server"}
package.json
:
"config": { "myPort": "8080"}
script.js
:
// defaulting to 8080 in case if script invoked not via "npm run-script" but directlyvar port = process.env.npm_package_config_myPort || 8080
npm start
npm
npm config set myPackage:myPort 9090
npm start
package.json
TA贡献1811条经验 获得超6个赞
package.json
:
"scripts": { "cool": "./cool.js"}
cool.js
:
console.log({ myVar: process.env.npm_config_myVar });
npm --myVar=something run-script cool
{ myVar: 'something' }
process.env.npm_config_
better-npm-run
process.env.npm_config_myVar
process.env.npm_config_myvar
添加回答
举报