Today I learned

Running NPM tasks in parallel

Update (2019): Consider solutions like npm-run-all which will accomplish the things below but in a cross-platform manner.

You can run multiple NPM script tasks in parallel. This is great for tasks like running build watchers. Just use the bash construct & to put each command in the background, then finally add wait so they can be terminated with ^C. The final syntax would be:

command1 & command2 & wait

In practice, this looks like so:

  "scripts": {
    "watch": "npm run watch:js & npm run watch:css & wait",
    "watch:js": "watchify -v -t babelify -s Editor index.js -o dist/index.js",
    "watch:css": "stylus -w css/style.styl -o dist/index.css",

You have just read Running NPM tasks in parallel, written on November 23, 2015. This is Today I Learned, a collection of random tidbits I've learned through my day-to-day web development work. I'm Rico Sta. Cruz, @rstacruz on GitHub (and Twitter!).

← More articles