如何并行运行多个 npm 脚本? [英] How can I run multiple npm scripts in parallel?

查看:50
本文介绍了如何并行运行多个 npm 脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 package.json 中,我有这两个脚本:

In my package.json I have these two scripts:

  "scripts": {
    "start-watch": "nodemon run-babel index.js",
    "wp-server": "webpack-dev-server",
  }

每次开始使用 Node.js 进行开发时,我都必须并行运行这两个脚本.我首先想到的是添加这样的第三个脚本:

I have to run these 2 scripts in parallel everytime I start developing in Node.js. The first thing I thought of was adding a third script like this:

"dev": "npm run start-watch && npm run wp-server"

...但是在运行 wp-server 之前会等待 start-watch 完成.

... but that will wait for start-watch to finish before running wp-server.

如何并行运行这些命令?请记住,我需要查看这些命令的输出.此外,如果您的解决方案涉及构建工具,我宁愿使用 gulp 而不是 grunt,因为我已经在另一个项目中使用了它.

How can I run these in parallel? Please keep in mind that I need to see the output of these commands. Also, if your solution involves a build tool, I'd rather use gulp instead of grunt because I already use it in another project.

推荐答案

使用名为 concurrently 的包.

npm i concurrently --save-dev

然后设置你的 npm run dev 任务:

Then setup your npm run dev task as so:

"dev": "concurrently --kill-others "npm run start-watch" "npm run wp-server""

这篇关于如何并行运行多个 npm 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆