From 6477492f62696e0d29fae0be2e77971566f64c7d Mon Sep 17 00:00:00 2001 From: Arunoda Susiripala Date: Mon, 7 Aug 2017 12:36:24 +0530 Subject: [PATCH] Move NPM modules out of the commons chunk in dev mode. (#2716) This is only a dev feature and it removes an error in HMR. Otherwise it'll throw an error with undefined error in the webpack core. --- server/build/webpack.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/server/build/webpack.js b/server/build/webpack.js index 13b6d660..8ce71291 100644 --- a/server/build/webpack.js +++ b/server/build/webpack.js @@ -94,14 +94,6 @@ export default async function createCompiler (dir, { dev = false, quiet = false, name: 'commons', filename: 'commons.js', minChunks (module, count) { - // In the dev we use on-demand-entries. - // So, it makes no sense to use commonChunks based on the minChunks count. - // Instead, we move all the code in node_modules into this chunk. - // With that, we could gain better performance for page-rebuild process. - if (dev) { - return module.context && module.context.indexOf('node_modules') >= 0 - } - // We need to move react-dom explicitly into common chunks. // Otherwise, if some other page or module uses it, it might // included in that bundle too. @@ -109,6 +101,13 @@ export default async function createCompiler (dir, { dev = false, quiet = false, return true } + // In the dev we use on-demand-entries. + // So, it makes no sense to use commonChunks based on the minChunks count. + // Instead, we move all the code in node_modules into each of the pages. + if (dev) { + return false + } + // If there are one or two pages, only move modules to common if they are // used in all of the pages. Otherwise, move modules used in at-least // 1/2 of the total pages into commons.