webpack-dev-server hot reload with existing server

After spending ages trying to proxy requests to an express server with no luck (everything worked apart from no refresh), I decided to take a different, much simpler approach.

I’m now just running webpack-dev-server CLI like so:

 $ webpack-dev-server --inline --hot --no-info 

On your express server, point your bundle.js file to the webpack-dev-server port.

 <script src="<% if (settings.env === 'development') { %>http://localhost:8080<% } %>/public/assets/dist/js/bundle.js"></script> 

You can then go to your express server port (localhost:3000) and it should be working.

To tidy things up, I moved this to a bash file:

/bin/dev

#!/bin/bash

nodemon &
webpack-dev-server --inline --hot --no-info

package.json

{
    "scripts": {
        "dev": "./bin/dev",
    }
}

Then you can just run:

 $ npm run dev