1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Move all the modules used in 1/2 of all pages into the common chunks. (#1659)

This commit is contained in:
Arunoda Susiripala 2017-04-08 00:09:00 +05:30 committed by Guillermo Rauch
parent 0007cd2a97
commit 060cac3e3f

View file

@ -36,7 +36,7 @@ export default async function createCompiler (dir, { dev = false, quiet = false,
const mainJS = dev
? require.resolve('../../client/next-dev') : require.resolve('../../client/next')
let minChunks
let totalPages
const entry = async () => {
const entries = {
@ -68,8 +68,7 @@ export default async function createCompiler (dir, { dev = false, quiet = false,
}
}
// calculate minChunks of CommonsChunkPlugin for later use
minChunks = Math.max(2, pages.filter((p) => p !== documentPage).length)
totalPages = pages.filter((p) => p !== documentPage).length
return entries
}
@ -101,9 +100,8 @@ export default async function createCompiler (dir, { dev = false, quiet = false,
return module.context && module.context.indexOf('node_modules') >= 0
}
// NOTE: it depends on the fact that the entry funtion is always called
// before applying CommonsChunkPlugin
return count >= minChunks
// Move modules used in at-least 1/2 of the total pages into commons.
return count >= totalPages * 0.5
}
}),
// This chunk contains all the webpack related code. So, all the changes