verekia / js-stack-from-scratch

🛠️⚡ Step-by-step tutorial to build a modern JavaScript stack.
MIT License
20.07k stars 1.99k forks source link

run yarn start and yarn dev:wds in one command #197

Open berkin opened 7 years ago

berkin commented 7 years ago

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:*"

{
  "start": "npm-run-all -p dev:start dev:wds
}
verekia commented 7 years ago

Awesome. Thank you for bringing that up!

mbsrc commented 6 years ago

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.

verekia commented 6 years ago

I'm using it too, it's great :) Particularly with the shorthand run-p and run-s for shorter commands.