-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Say my app is served on port 3000, and I have webpack dev server running on port 45537. I'm only using the dev server for assets/hot reloading, not serving the html files, that is taken care of by something else (django, rails, whatever). The thing is, I may access this app using different hostnames or IPs (e.g. localhost
, 10.0.2.2
, the internal network IP of the server) so I want the hot reloading stuff to work no matter how/where I am accessing the app.
Command used to start webpack-dev-server:
webpack-dev-server --config webpack.hot.config.js --host 0.0.0.0 --port 45537 --hot --no-info
conifg:
const path = require('path');
module.exports = {
entry: [
'webpack-dev-server/client?http://0.0.0.0:45537',
'webpack/hot/only-dev-server',
path.join(__dirname, 'src', 'js', 'app.js'),
],
module: {
loaders: [
{
exclude: /node_modules/,
loaders: ['react-hot', 'babel-loader'],
test: /\.js$/,
},
],
},
output: {
filename: 'app.js',
publicPath: '/',
},
};
In my html file, I have this at the bottom to load webpack-dev-server.js and my app bundle:
<script>
!function() {
var host = location.host.split(':')[0];
document.write(
'<script src="http://' + host + ':45537/app.js"></' + 'script>'
);
}()
</script>
The problem is when I reload a file, it tries to grab the manifest from port 3000 instead of 45537:
[WDS] App updated. Recompiling...
[WDS] App hot update...
[HMR] Checking for updates on the server...
GET http://192.168.1.45:3000/0f047ad04fb3ea0a8b54.hot-update.json 404 (Not Found)
Of course, specifing the publicPath
as http://localhost:45537/
would only work if I am on the same computer as the dev server, so that's not what I am looking for.