npm 允许在package.json文件里面,使用scripts字段定义脚本命令。
{
"name": "ng2",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"install": "napa",
"start": "ng serve",
"abc": "ng generate component MyGridApplication",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"modernizr": "modernizr -c modernizr-config.json -d src/modernizr.js",
"postinstall": "node ./node_modules/protractor/bin/webdriver-manager update",
"e2e": "ng e2e"
},
"private": true,
"napa": {
"jquery.flot.spline": "miloszfalinski/jquery.flot.spline",
"ika.jvectormap": "kakirigi/ika.jvectormap"
},
"dependencies": {
"@agm/core": "1.0.0-beta.0",
"@angular/animations": "4.0.2"
},
"devDependencies": {
"@angular/cli": "1.0.0",
"@angular/compiler-cli": "4.0.2",
"@types/codemirror": "0.0.38"
}
}
上面代码是package.json文件,里面的scripts字段是一个对象。它的每一个属性,对应一段脚本或者一个指令。
比如,abc命令对应的脚本是<code>ng generate component MyGridApplication </code>我们如果要执行abc指令应该这样运行<code>npm run abc</code>这样就执行了<code>ng generate component MyGridApplication</code>指令 或者也可以<code>npm run ng generate component MyGridApplication</code>这样相当于执行了 script里面的ng指令
<h6 align = "right">sivona</h6>