npm_config_
npm config
2023-09-14 08:58:55 时间
npm script时会带一些参数变量,例如:
"test": "node scripts/tools/test.js --name=test111"
平常我们执行npm run dev,想要获取后面的参数,只能通过
console.log(process.argv)
打印出来的是这样的
[ 'C:\\Program Files\\nodejs\\node.exe', 'D:\\workspace\\xxxx\\scripts\\test.js', '--name=test111' ]
明显不是我们想要的,我们想直接获取test111
那么我们在试下,跑npm run dev --name=test222
然后打印一下看看:
console.log(process.argv)
console.log(process.env.npm_config_name)
打印出来的是这样的
[ 'C:\\Program Files\\nodejs\\node.exe', 'D:\\workspace\\scripts\\test.js', '--name=test111' ] test222
我们可以通过 npm_config_ 来直接方便地获取参数了~
相关文章
- window 安装使用npm
- 2-1 nodejs和npm的安装和环境搭建
- Web前端 -- NPM包管理器
- [NPM + React] Prepare a Custom React Hook to be Published as an npm Package
- [NPM] Publish npm packages using npm publish
- [NPM] Create a node script to replace a complex npm script
- [NPM] Run npm scripts when files change with onchange
- [NPM] Use a shorthand syntax for running multiple npm scripts with npm-run-all
- [NPM] Run npm scripts in parallel
- [Node.js] Using npm link to use node modules that are "in progress"
- Angularjs学习---angularjs环境搭建,ubuntu 12.04下安装nodejs、npm和karma
- [NPM] npm check to update the dependencies
- [NPM] Create a new project using the npm init <initializer> command
- [NPM] List available npm scripts and support tab completion
- [NPM] Make npm scripts cross-environment friendly
- [NPM] Run npm scripts in parallel
- [NPM] Run npm scripts in series
- [NPM] Use package.json variables in npm scripts
- npm warn config global `--global`, `--local` are deprecated. use `--location=global` instead.
- npm install过程中遇到typings deprecated的warning该怎么处理
- npm run dev 启动错误:Module build failed: Error: No PostCSS Config found in:xxxxxxxxxxxxxx
- npm init node 通过指令创建一个package.json文件及npm安装package.json
- 解决 npm -v 出现空白行 没反应的方法