提交 060cac3e 编写于 作者: A Arunoda Susiripala 提交者: Guillermo Rauch

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

上级 0007cd2a
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册