diff --git a/CHANGELOG.md b/CHANGELOG.md index 593d909..fb66134 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ ## Webpack4 - React16.7 Templater App +# 2.1.2 + * Fixed HMR work in development mode. + # 2.1.1 * Update UjlifyJS plugin correspond to its internal update. * Improved distinguish between prod and dev version running via Hot Module Replacement. diff --git a/server/server.ts b/server/server.ts index 4d9ecd9..ea4813f 100644 --- a/server/server.ts +++ b/server/server.ts @@ -15,7 +15,7 @@ const bundler = webpack(webpackConfig); // ======================================================== const devMiddlewareOptions = { publicPath: webpackConfig.output.publicPath, - hot: globals.__DEV__ ? true : false, + hot: __DEV__ ? true : false, headers: { 'Access-Control-Allow-Origin': '*' } }; @@ -24,7 +24,7 @@ const devMiddlewareOptions = { // ======================================================== const webpackMiddleware = [webpackDevMiddleware(bundler, devMiddlewareOptions)]; -if (globals.__DEV__) { +if (__DEV__) { webpackMiddleware.push(webpackHotMiddleware(bundler)); } diff --git a/webpack.config.js b/webpack.config.js index 350c98c..fde5e84 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -213,13 +213,13 @@ const createConfig = () => { // ------------------------------------ // Entry Points // ------------------------------------ - const appEntryPoint = ['babel-polyfill', path.resolve(__dirname, 'src/index.js')]; + const appEnterPrefixPlugins = ['babel-polyfill']; + const appPath = path.resolve(__dirname, 'src/index.js'); + const appEntryPoint = [...appEnterPrefixPlugins, appPath]; - if (__DEV__) { - const HMRPath = 'webpack-hot-middleware/client?path=/__webpack_hmr'; - - appEntryPoint[1].concat(HMRPath); - } + webpackConfig.entry = { + app: __DEV__ ? appEntryPoint.concat('webpack-hot-middleware/client?path=/__webpack_hmr') : appEntryPoint + }; webpackConfig.entry = { app: appEntryPoint