How to run multiple npm scripts in parallel?
P粉807239416
P粉807239416 2023-08-23 17:10:35
0
2
505
<p>In my <code>package.json</code> I have these two scripts: </p> <pre class="brush:php;toolbar:false;">"scripts": { "start-watch": "nodemon run-babel index.js", "wp-server": "webpack-dev-server", }</pre> <p>Every time I start developing in Node.js, I have to run these two scripts <strong>in parallel</strong> My first thought was to add a third script like this: </p> <pre class="brush:php;toolbar:false;">"dev": "npm run start-watch && npm run wp-server"</pre> <p>...but this will wait for <code>start-watch</code> to complete before running <code>wp-server</code>. </p> <p><strong>How can I run these commands in parallel? </strong>Keep in mind that I need to see the <code>output</code> of these commands. Also, if your solution involves build tools, I'd rather use <code>gulp</code> than <code>grunt</code> since I'm already using it in another project. </p>
P粉807239416
P粉807239416

reply all(2)
P粉026665919

If you are using a UNIX-like environment, just use & as the delimiter:

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

Otherwise, if you are interested in a cross-platform solution, you can use the npm-run-all module:

"dev": "npm-run-all --parallel start-watch wp-server"
P粉143640496

Use a package named Concurrency.

npm i concurrently --save-dev

Then set up your npm run dev task as follows:

"dev": "concurrently --kill-others \"npm run start-watch\" \"npm run wp-server\""
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template