字段指定了两项命令 start ,输入
npm run-script start 或者
npm run start ,就会执行 someTool build 。
npm run 是
npm run-script 的缩写,一般都使用前者,但是后者可以更好地反应这个命令的本质。
npm run 命令会自动在环境变量
$PATH 添加
node_modules/.bin 目录,所以
scripts 字段里面调用命令时不用加上路径,这就避免了全局安装NPM模块。
npm run 如果不加任何参数,直接运行,会列出
package.json 里面所有可以执行的脚本命令。npm内置了两个命令简写,
npm test 等同于执行
npm run test ,
npm start 等同于执行
npm run start 。
npm run 会创建一个Shell,执行指定的命令,并临时将
node_modules/.bin 加入PATH变量,这意味着本地模块可以直接运行。举例来说,你执行ESLint的安装命令。
$ npm i eslint --save-dev运行上面的命令以后,会产生两个结果。首先,ESLint被安装到当前目录的
node_modules 子目录;其次,
node_modules/.bin 目录会生成一个符号链接
node_modules/.bin/eslint ,指向ESLint模块的可执行脚本。然后,你就可以在
package.json 的
script 属性里面,不带路径的引用
eslint 这个脚本。
{
"name": "Test Project",
"devDependencies": {
"eslint": "^1.10.3"
},
"scripts": {
"lint": "eslint ."
}
}等到运行
npm run lint 的时候,它会自动执行
./node_modules/.bin/eslint . 。如果直接运行
npm run 不给出任何参数,就会列出
scripts 属性下所有命令。
$ npm run
Available scripts in the user-service package:









