If you want a platform-independent way to run multiple npm scripts with a single command, without shell hacks or editor specific tasks, use npm-run-all2
. It’s a maintained fork of npm-run-all and a drop-in replacement with the same commands: run-p
, run-s
, and npm-run-all
.
This guide shows practical examples you can paste into package.json
.
Why npm-run-all2?
It is cross-platform: works the same on macOS, Linux, and Windows and it has simple shorthands:
-
run-p
- run scripts in parallel -
run-s
- run scripts in sequence
Useful flags: labels, glob patterns, race mode, continue-on-error, and max concurrency: --race, --continue-on-error, --max-parallel, --print-label
.
Install
If you've never used the original:
npm i -D npm-run-all2
Migrating from npm-run-all
:
npm remove npm-run-all
npm i -D npm-run-all2
Usage (in parallel)
Use parallel for independent long-running tasks (e.g., dev servers, watchers). Let's say you have this in your package.json
file:
{
"scripts": {
"frontend": "cd frontend && npm run dev",
"backend": "cd backend && npm run start:dev",
"start:dev": "run-p frontend backend"
}
}
Now, if you run
npm run start:dev
you will have both the backend and the frontend servers up and running.
Usage (in sequence)
Use sequential when you need to run scripts in sequence (e.g. format > lint > compile). Let's say you have this in your package.json
file:
{
"scripts": {
"format": "prettier --write",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"compile": "tsc -p tsconfig.json",
"build": "run-s format lint compile"
}
}
Now, if you run
npm run build
you will have basically executed three commands one after the other: npm run format > npm run lint > npm run compile.
More information
You can find more usage patterns and combinations here at these URLs:
Top comments (0)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.