Skip to content

Commit adfadef

Browse files
committed
Fixed HMR work in development mode.
1 parent 850a8e6 commit adfadef

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
## Webpack4 - React16.7 Templater App
22

33

4+
# 2.1.2
5+
* Fixed HMR work in development mode.
6+
47
# 2.1.1
58
* Update UjlifyJS plugin correspond to its internal update.
69
* Improved distinguish between prod and dev version running via Hot Module Replacement.

server/server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const bundler = webpack(webpackConfig);
1515
// ========================================================
1616
const devMiddlewareOptions = {
1717
publicPath: webpackConfig.output.publicPath,
18-
hot: globals.__DEV__ ? true : false,
18+
hot: __DEV__ ? true : false,
1919
headers: { 'Access-Control-Allow-Origin': '*' }
2020
};
2121

@@ -24,7 +24,7 @@ const devMiddlewareOptions = {
2424
// ========================================================
2525
const webpackMiddleware = [webpackDevMiddleware(bundler, devMiddlewareOptions)];
2626

27-
if (globals.__DEV__) {
27+
if (__DEV__) {
2828
webpackMiddleware.push(webpackHotMiddleware(bundler));
2929
}
3030

webpack.config.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,13 @@ const createConfig = () => {
213213
// ------------------------------------
214214
// Entry Points
215215
// ------------------------------------
216-
const appEntryPoint = ['babel-polyfill', path.resolve(__dirname, 'src/index.js')];
216+
const appEnterPrefixPlugins = ['babel-polyfill'];
217+
const appPath = path.resolve(__dirname, 'src/index.js');
218+
const appEntryPoint = [...appEnterPrefixPlugins, appPath];
217219

218-
if (__DEV__) {
219-
const HMRPath = 'webpack-hot-middleware/client?path=/__webpack_hmr';
220-
221-
appEntryPoint[1].concat(HMRPath);
222-
}
220+
webpackConfig.entry = {
221+
app: __DEV__ ? appEntryPoint.concat('webpack-hot-middleware/client?path=/__webpack_hmr') : appEntryPoint
222+
};
223223

224224
webpackConfig.entry = {
225225
app: appEntryPoint

0 commit comments

Comments
 (0)