Skip to content

Commit 5b0b78a

Browse files
committed
Fix Webpack Hot Reload error (issue #3):
Update webpack configuration to specify output.publicPath with webpack port loaded from dotenv. Update index to allow for re-rendering application on hot-reload. Include NamedModulesPlugin to provide module names instead of numbers.
1 parent 9a2f789 commit 5b0b78a

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

client/src/index.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,19 @@ window.store = store
2121
// bootstrap state
2222
store.dispatch(fetchMe());
2323

24-
ReactDOM.render(
25-
<App store={store} />,
26-
document.getElementById('root')
27-
);
24+
// renderApp function for hot reloading
25+
const renderApp = App => {
26+
const NextApp = require('./components/App').default;
27+
ReactDOM.render(
28+
<NextApp store={store} />,
29+
document.getElementById('root')
30+
);
31+
}
32+
33+
// hot loading
34+
if (module.hot) {
35+
module.hot.accept("./components/App", () => { renderApp(App) })
36+
}
37+
38+
// initial render
39+
renderApp(App)

webpack.config.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
require('dotenv').config()
3+
require('dotenv').config();
44
var webpack = require('webpack');
55
var path = require('path');
66

@@ -14,6 +14,7 @@ var config = {
1414
output: {
1515
path: BUILD_DIR,
1616
filename: 'app.js',
17+
publicPath: `http://localhost:${process.env.WEBPACK_PORT}/`,
1718
},
1819
module: {
1920
loaders : [
@@ -30,7 +31,8 @@ var config = {
3031
]
3132
},
3233
plugins: [
33-
new webpack.HotModuleReplacementPlugin()
34+
new webpack.HotModuleReplacementPlugin(),
35+
new webpack.NamedModulesPlugin()
3436
],
3537

3638
devServer: {

0 commit comments

Comments
 (0)