[NPM] Avoid Duplicate Commands by Calling one NPM Script from Another

We can get a lot of utility through CLI tools invoked via npm scripts. Many of these tools have APIs with many flags and options, meaning we will frequently find ourselves using the same CLI tool in multiple npm scripts, often with only minor differences. In this lesson, we'll take two very similar npm scripts and see how to remove the duplication by calling one script from another and passing in additional flags.

From:

"scripts": {
  ...
  "dev": "webpack-dev-server --open --config webpack.config.dev.js",
  "dev:hot": "webpack-dev-server --open --hot --config webpack.config.dev.js"
}

To:

"dev": "webpack-dev-server --open --config webpack.config.dev.js",
"dev:hot": "npm run dev -- --hot",

RUN:

$ npm run dev --hot

猜你喜欢

转载自www.cnblogs.com/Answer1215/p/10397478.html
NPM