How to run multiple npm scripts in parallel?
P粉807239416
2023-08-23 17:10:35
<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>
If you are using a UNIX-like environment, just use
&
as the delimiter:Otherwise, if you are interested in a cross-platform solution, you can use the npm-run-all module:
Use a package named Concurrency.
Then set up your
npm run dev
task as follows: