使用NPM构建命令启动时,以下脚本如何工作

时间:2016-12-08 18:32:55

标签: node.js npm webpack tsc

我有package.JSON文件,其中提到了脚本,

 "scripts": {
    "typings": "typings install",
    "build": "tsc && webpack",
    "watch": "npm-run-all -p -r -l tsc-watch webpack-watch",
    "tsc-watch": "tsc -w",
    "webpack-watch": "webpack -w",
    "clean": "rm -rf built",
    "minify": "webpack --optimize-minimize --optimize-dedupe",
    "start": "http-server -p 8000",
    "pretest": "tsc -p tests",
    "test": "mocha test/tests",
    "foo": "mocha test/tests"
  },

当npm用作带命令的构建时,“run start build”,脚本执行顺序

1 个答案:

答案 0 :(得分:1)

正在运行npm run start build将首先运行"start": "http-server -p 8000",,然后运行"build": "tsc && webpack",。虽然这里的 start 命令是一个http服务器,并且在取消之前永远不会返回,但它永远不会调用下一个命令。

NPM run命令也称为run-script,允许运行package.json文件中定义的任意命令。

参考:https://docs.npmjs.com/misc/scriptshttps://docs.npmjs.com/cli/run-script