How can I run a webpack-dev-server instance AND a node.js instance?

I’ve remixed a project setup for running webpack-dev-server and another one with a node server,
it seems as it’s the scripts.start setting in package.json that drives the running process for the app

“scripts”: {
“start”: “node server.js”
},

“scripts”: {
“start”: “webpack-dev-server”
},

What would be the best way of having the two processes running at all times ?

javascript - How can I run multiple npm scripts in parallel? - Stack Overflow

We’d suggest the following:

"scripts": { "start": "bash start-all.sh" } and then in the file start-all.sh:

#!/bin/bash

npm run start-watch &
npm run wp-server &

wait

but concurrently works too.

2 Likes

Thanks, I managed to get it working by setting up a node server, and adding webpack-dev-middleware within it

if (isDev) {
  const webpack = require('webpack');
  const webpackDevMiddleware = require('webpack-dev-middleware');
  const config = require('./webpack.config.js');
  const compiler = webpack(config);
  require("babel-core").transform("code", {
    plugins: ["transform-react-jsx"]
  });

  app.use(webpackDevMiddleware(compiler, {
    publicPath: config.output.publicPath
  }));  
}

I have this as a start script (in dev mode)

 "start": "nodemon server.js --exec babel-node --presets es2015,react"

It works. but your solution is perhaps better, It’s nice that there are options !

1 Like