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