Anu*_*wan 7 node.js npm package.json
我正在尝试访问 npm 脚本本身中的环境变量,如下所示:
"scripts": {
"test": "istanbul cover node_modules/.bin/_mocha --root ../SERVER/routes -- --recursive"
},
Run Code Online (Sandbox Code Playgroud)
并像这样启动这个脚本:
SERVER=somewhere npm test
Run Code Online (Sandbox Code Playgroud)
如何SERVER
在 package.json 本身的 npm 脚本中获取变量的解析值?
对于 Windows 用户,您可以像这样使用变量:%SERVER%
而不是$SERVER
.
或者更好的使用cross-env
模块的方法,这将允许您在所有平台上像 linux 一样执行此操作:
npm i cross-env
Run Code Online (Sandbox Code Playgroud)
并使用它:
"scripts": {
"test": "cross-env-shell \"istanbul cover node_modules/.bin/_mocha --root ../$SERVER/routes -- --recursive\""
}
Run Code Online (Sandbox Code Playgroud)
使用$SERVER
对你有用吗?
"scripts": {
"test": "istanbul cover node_modules/.bin/_mocha --root ../$SERVER/routes -- --recursive"
}
归档时间: |
|
查看次数: |
11566 次 |
最近记录: |