简体   繁体   English

如何使用watch按顺序运行多个NPM脚本

[英]How to run multiple NPM scripts in sequence with watch

I am working on angular 7 application.我正在研究 angular 7 应用程序。 Below are the scripts in my package.json file to build the application以下是我的 package.json 文件中用于构建应用程序的脚本

"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.我想按顺序运行 build:dev 和 postbuild 命令。 so first command builds the application by updating the dist folder with bundle files.所以第一个命令通过使用捆绑文件更新 dist 文件夹来构建应用程序。 To move the bundle files to separate folders, we have created a fileMover.js node script.为了将捆绑文件移动到单独的文件夹,我们创建了一个 fileMover.js 节点脚本。

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.没有 --watch,build:all 脚本工作正常,但由于这一点,我们需要在每次进行任何更改时手动运行命令并通过 Visual Studio 或其他工具保存。 With watch, it never runs the second "postbuild" command.使用 watch,它永远不会运行第二个“postbuild”命令。

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.我相信,您可以将&更改为&&作为单个&用于并行运行,而 double 用于一个接一个地运行。

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:您还可以使用 'pre' 和 'post' 词缀:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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