I have a front-end application bundled with webpack, which is served by and talks to a Node backend server.
Webpack hot dev server is running on 8080
.
Node backend is running on 1985
.
I want to serve index.html
from Node, but want assets served from the hot dev server during development. To achieve this I have:
Set an absolute publicPath value in webpack config:
output: {
publicPath: 'http://localhost:8080/'
},
And used absolute URLs in index.html
to point to the hot dev server:
<script src="http://localhost:8080/webpack-dev-server.js"></script>
<script src="http://localhost:8080/js/vendors.js"></script>
<script src="http://localhost:8080/js/bundle.js"></script>
So I can run the hot dev server and run my Node server and browse to http://localhost:1985
. Everything is great.
But when I come to deploy / run in production, this is definitely not what I want. I'd like relative URLs for vendors.js
and bundle.js
and I definitely don't want to include the webpack-dev-server.js
script.
I could use Handlebars or some other templating on the server to specify the absolute / relative paths, but it wouldn't provide a clean way of removing the hot dev server script. I could also have different index files for each setup, but this seems like it would quickly lead to bugs.
How can this be best be structured / deployed to enable use of the hot dev server in development, while still allowing for the whole thing to be deployed and served via Node in production?