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

Add dependencies of _app.js to commons (#4396)

Since `_app.js` is used on every page it makes sense to move it's dependencies to the `commons.js` so that if you require a dependency in `_app.js` and in one of your pages it is not included twice in your bundles. 

This PR modifies the `CommonsChunkPlugin` to move every module that is used in `_app.js` and at least in one other bundle.
This commit is contained in:
Robert van Steen 2018-06-07 13:12:48 +02:00 committed by Tim Neutkens
parent 3684231add
commit 2af4ad8b17

View file

@ -193,6 +193,19 @@ export default async function getBaseWebpackConfig (dir, {dev = false, isServer
return false
}
// Check if the module is used in the _app.js bundle
// Because _app.js is used on every page we don't want to
// duplicate them in other bundles.
const chunks = module.getChunks()
const inAppBundle = chunks.some(chunk => chunk.entryModule
? chunk.entryModule.name === 'bundles/pages/_app.js'
: null
)
if (inAppBundle && chunks.length > 1) {
return true
}
// commons
// 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