mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
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.
This commit is contained in:
parent
256f9dc765
commit
6477492f62
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue