-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Dynamic hostname and port of hot update manifest #262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
You can set the __webpack_public_path__ = 'http://' + host + ':45537/js/' |
I don't understand. I followed http://webpack.github.io/docs/configuration.html#output-publicpath, (the warning about the Hot Module Replace Plugin needing to be disabled scares me, if I can't use HMR then what's the point of this?) and created a file called var host = window.location.host.split(':')[0];
__webpack_public_path__ = 'http://' + host + ':45537/'; and then I modified my entry list to include it: entry: [
'./webpack.init.js',
'webpack/hot/only-dev-server',
path.join(__dirname, 'src', 'js', 'app.js'),
], That didn't seem to affect anything. |
The note is wrong, I removed it. hmmm... it should work that way. |
Yeah I see the source code says function hotDownloadManifest(callback) { // eslint-disable-line no-unused-vars
/******/ if(typeof XMLHttpRequest === "undefined")
/******/ return callback(new Error("No browser support"));
/******/ try {
/******/ var request = new XMLHttpRequest();
/******/ var requestPath = __webpack_require__.p + "" + hotCurrentHash + ".hot-update.json"; and with my /* 1 */
/***/ function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(module) {/* REACT HOT LOADER */ if (true) { (function () { var ReactHotAPI = __webpack_require__(3), RootInstanceProvider = __webpack_require__(11), ReactMount = __webpack_require__(13), React = __webpack_require__(67); module.makeHot = module.hot.data ? module.hot.data.makeHot : ReactHotAPI(function () { return RootInstanceProvider.getRootInstances(ReactMount); }, React); })(); } try { (function () {
'use strict';
var host = window.location.host.split(':')[0];
__webpack_require__.p = 'http://' + host + ':45537/'; Seems like it should work. But |
I think I need to modify /******/ function hotCreateRequire(moduleId) { // eslint-disable-line no-unused-vars
/******/ var me = installedModules[moduleId];
/******/ if(!me) return __webpack_require__;
/******/ var fn = function(request) { Whatever |
My config is a bit different than yours. I just run Here are the relevant parts of my config:
|
Thanks @aaronjensen. I think I see why it's working for you but not for me. You are actually accessing the html page served by the dev-server (so same port as the assets) whereas I am only using the dev-server to serve assets and I'm using some other app (and port) to serve the html, so hot reloading would work in your case because the url of the manifest that webpack tries to grab will have the correct port. |
Hi @kentor, good, hope that helps you get sorted. FWIW, we actually are on different ports than the browser sees as well because of browser-sync, so I do this: <script>
var devServer = document.createElement('script');
devServer.setAttribute('src', 'http://' + window.location.host.replace('4000', '4001') + '/webpack-dev-server.js');
document.body.appendChild(devServer);
</script> Note the |
@aaronjensen Ah ok. I can load In your case, it would try port 4000 instead of 4001 to grab the manifest file, no? |
@kentor yes, you're right. And since browser-sync proxies to webpack-dev-server, this works for me. If your server isn't proxying, that won't work 😦 This whole thing is a bit more complicated than it seems it should be. |
I'm using browserify-hmr now since that allows changing the websocket url at runtime so I'm going to close this. Thanks for the help anyway! |
I'm having the same problem, though my setup is a bit different from what @kentor was using. I'm using Cordova and serving my HTML file directly from the file system and requests JS from the devserver. By specifying the host to the devservers IP I managed to get the polling working. But when downloading the manifest it tries to download the JSON from the Android device:
It would be really nice if this could be solved somehow. Hot reloading when working with mobile devices would be really neat. Thanks! |
I have the same problem here, I'm using Symfony as a front end and webpack to serve assets. |
Has anyone found a solution for this? I am also having this issue where webpack is only serving static files and the application is being served by node/python/ruby etc... |
Had same issue and was able to get over it using this advice from https://github.com/gaearon/react-hot-loader/blob/master/docs/Troubleshooting.md
Also, note the CORS headers webpack-dev-server config.
|
Try this: output: {
path: path.resolve(ROOT_PATH, 'public/assets'),
publicPath: `http://0.0.0.0:${DEV_SERVER_PORT}/assets/`,
filename: '[name].js',
}, |
@alexkuz ^^^ the above works while running alongside a rails app served separately |
@nathanmarks thank you for reference, but I think this is another case. devServer: {
proxy: {
'/api/*': {
target: config.proxyBaseUrl, // this should be reloadable
secure: false,
changeOrigin: true,
alterProxyOptions: true
}
}
} If I get it right, the above is not related to this. |
In my case (for browser-sync) I had to use |
For Cordova the app runs at In the webpack config I have output Finally in the entry JS file I have something like this:
|
So what was the resolution here. @kentor do you remember how you overcame this issue? |
@thenewguy you will need
and you may need
|
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:
conifg:
In my html file, I have this at the bottom to load webpack-dev-server.js and my app bundle:
The problem is when I reload a file, it tries to grab the manifest from port 3000 instead of 45537:
Of course, specifing the
publicPath
ashttp://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.The text was updated successfully, but these errors were encountered: