This command: "start": "node server/server.js"
starts my server, but before running this I also want a command to run automatically: 'webpack'
.
I want to build a script that can be run with npm run someCommand
- it should first run webpack
in the terminal, followed by node server/server.js
.
(I know how configure this with gulp, but I don't want to use it)
&& will run your scripts sequentially while & will run them in parallel. A quick way of doing it is npm run start-watch & npm run wp-server . This will run the first command as a background thread. This works really well when one of the commands is not long running and does not need to be manually exited later.
If I understood you correctly, you want firstly run webpack and after compile run nodejs. Maybe try this:
"start": "webpack && node server/server.js"
The following should work:
"start": "webpack && node server/server.js"
Though, for readability (and especially if you plan on adding additional tasks in the future), you may want to consider creating separate entries for each task and then calling each of those from start
. Something like:
{ "init-assets": "webpack", "init-server": "node server/server.js", "start": "npm run init-assets && npm run init-server" }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With