【发布时间】:2016-03-05 18:55:48
【问题描述】:
案例1:使用变量名代替值
package.json:
{
"name": "example",
"config": {
"url": "localhost/dev"
},
"scripts": {
"watch": "browser-sync start --files \"./**/*, !.node_modules/, !src\" --proxy $npm_package_config_url"
}
}
$npm run watch 在浏览器中打开http://localhost:3000/$npm_package_config_url,而不是http://localhost:3000/dev
所以,$npm_package_config_url 被用作字符串,而不是变量。
案例 2: 命令替换不起作用
{
{ ... },
"scripts": {
"rm:all": "npm rm $(ls -1 node_modules | tr '/\\n' ' ')"
}
}
子命令列出 node_modules 中的文件夹。
同样,npm run rm:all 什么也不做,因为 $(ls -1 node_modules | tr '/\\n' ' ') 被解释为文件夹名称。
环境:Windows 10 | npm 3.5.1 |节点 4.2.2 | git-bash 2.6.0
【问题讨论】:
标签: node.js windows npm git-bash package.json