关于package.json 的script标签使用以及和npm的关系

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命令对应的脚本是ng generate component MyGridApplication 我们如果要执行abc指令应该这样运行npm run abc这样就执行了ng generate component MyGridApplication指令 或者也可以npm run ng generate component MyGridApplication这样相当于执行了 script里面的ng指令


sivona

你可能感兴趣的:(关于package.json 的script标签使用以及和npm的关系)