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


#1

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 ?

https://stackoverflow.com/questions/30950032/how-can-i-run-multiple-npm-scripts-in-parallel


#2

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.


#3

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 !