Right now I have to open two terminal windows to run both commands. I tried creating a combined script like this:
"develop": "npm run dev-server && npm run build-watch"
But this doesn’t work because it waits for the first command to complete before starting the second one. I need both processes running at the same time so I can develop effectively.
I want to see the console output from both commands while they’re running. If there’s a solution using build tools, I prefer gulp since I’m already familiar with it. What’s the most efficient approach to handle this?
npm-run-all is another option that’s cleaner than concurrently IMO. Just npm i -D npm-run-all then update your script to "develop": "npm-run-all --parallel dev-server build-watch". The --parallel flag runs both at the same time and handles ctrl+c properly to kill both processes.
Since you’re comfortable with gulp, you could handle this in gulpfile.js instead of package.json scripts. I’ve used gulp for similar setups and it gives you way more control. Create a gulp task that spawns both processes with child_process.spawn() and pipe their stdout to console with different prefixes. You’ll get real-time output from both commands without installing extra npm packages. Plus you can add error handling, restart logic, or conditional execution based on what you need. Just run gulp develop and both nodemon and webpack-dev-server start together.
You can run multiple npm commands at once using the ampersand operator (&) instead of double ampersand (&&). Both commands will start simultaneously, but you’ll have limited output control and cross-platform issues. Better option: use the concurrently package. Install it with npm install --save-dev concurrently and update your package.json script to: "develop": "concurrently \"npm run dev-server\" \"npm run build-watch\"". It color-codes output from each command so you can easily tell which logs come from where, plus it handles process termination properly.