Open berkin opened 7 years ago
Awesome. Thank you for bringing that up!
I've also been using npm-run-all for my dev/build scripts and found it to be very useful. It's a powerful little package with lots of flexibility that's simple to use and understand. Could be a good way to bring added value to your readers without over-bloating/complicating your project.
I usually run development scripts in parallel with yarn dev
using the dev:*
namespace and production scripts sequentially with yarn prod
and the prod:*
namespace. The code below is an adapted version of the scripts in the Webpack section of Chapter 04 using this approach:
scripts: {
"dev": "run-p dev:*",
"dev:start": "nodemon -e js,jsx --ignore lib --ignore dist --exec babel-node src/server",
"dev:wds": "webpack-dev-server --progress",
"prod": "run-s prod:*",
"prod:build": "rimraf lib dist && babel src -d lib --ignore .test.js && cross-env NODE_ENV=production webpack -p --progress",
"prod:start": "cross-env NODE_ENV=production pm2 start lib/server && pm2 logs",
"stop:prod": "pm2 delete server",
...
}
The production version of the project can still be built without running the pm2 server with yarn prod:build
.
Feel free to reach out if you decide to use this package and are looking for help with either updating code, testing, or documentation.
I'm using it too, it's great :) Particularly with the shorthand run-p
and run-s
for shorter commands.
Using a module like npm-run-all, it is possible to run multiple npm-scripts in parallel. Also it supports wildcard, the below script can be run as "npm-run-all -p dev:*"