简体   繁体   中英

How to run multiple NPM scripts in sequence with watch

I am working on angular 7 application. Below are the scripts in my package.json file to build the application

"scripts": {

       "build:all": "npm run build:dev & npm run postbuild",
       "build:dev": "ng build --extract-css --watch",
       "postbuild": "node fileMover.js",
   }

I want to run both build:dev and postbuild commands in sequence. so first command builds the application by updating the dist folder with bundle files. To move the bundle files to separate folders, we have created a fileMover.js node script.

without --watch, build:all script works fine but due to this, we need to manually run the command everytime we make any changes & save through visual studio or other tool. With watch, it never runs the second "postbuild" command.

Is there any alternate to run both scripts (fist with watch) in sequence?

Thanks :)

You could change the & to && as a single & is for running in parallel and double is for one after-the-other, I believe.

scripts": {
  "build:all": "npm run build:dev && npm run postbuild",
  "build:dev": "ng build --extract-css --watch",
  "postbuild": "node fileMover.js",
}

You could also use the 'pre' and 'post' affixes:

scripts": {
  "build:dev": "ng build --extract-css --watch",
  "build:all": "npm run build:dev",
  "postbuild:all": "node fileMover.js",
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM