让前端飞Web前端之路

npm script工作流(二)串行和并行

2020-08-04  本文已影响0人  ZoranLee

代码检查

单元测试

package.json配置如下:

{
  "name": "hello-npm-script",
  "version": "0.1.0",
  "main": "index.js",
  "scripts": {
    "lint:js": "eslint *.js",
    "lint:css": "stylelint *.less",
    "lint:json": "jsonlint --quiet *.json",
    "lint:markdown": "markdownlint --config .markdownlint.json *.md",
    "test": "mocha tests/"
  },
  "devDependencies": {
    "chai": "^4.1.2",
    "eslint": "^4.11.0",
    "jsonlint": "^1.6.2",
    "markdownlint-cli": "^0.5.0",
    "mocha": "^4.0.1",
    "stylelint": "^8.2.0",
    "stylelint-config-standard": "^17.0.0"
  }
}

多个npm 串行

scripts:{"test": "npm run lint:js && npm run lint:css && npm run lint:json && npm run lint:markdown && mocha tests/"}

多个npm 并行

"test": "npm run lint:js & npm run lint:css & npm run lint:json & npm run lint:markdown & mocha tests/"
npm run lint:js & npm run lint:css & npm run lint:json & npm run lint:markdown & mocha tests/ & wait

script 管理最佳实践

npm-run-all

npm i npm-run-all -D
"test": "npm-run-all lint:* mocha"
"test": "npm-run-all --parallel lint:* mocha"
上一篇下一篇

猜你喜欢

热点阅读