Unverified Commit 33d32eab authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Make chunk graph more accurate (#6923)

* Make chunk graph more accurate

* Include shared files in every page
parent 54f21e98
......@@ -46,12 +46,11 @@ function flatten<T>(arr: T[][]): T[] {
}
function getPossibleFiles(pageExtensions: string[], pages: string[]) {
const res = pages.map(page => {
const pi = path.join(page, 'index')
return [page, pi]
const res = pages.map(page =>
[page]
.concat(pageExtensions.map(e => `${page}.${e}`))
.concat(pageExtensions.map(e => `${pi}.${e}`))
})
.concat(pageExtensions.map(e => `${path.join(page, 'index')}.${e}`))
)
return flatten<string>(res)
}
......
......@@ -77,8 +77,8 @@ export class ChunkGraphPlugin implements Plugin {
hashes: {},
}
let clientRuntime = [] as string[]
let clientRuntimeChunks = [] as string[]
const sharedFiles = [] as string[]
const sharedChunks = [] as string[]
const pages: StringDictionary = {}
const pageChunks: StringDictionary = {}
const allFiles = new Set()
......@@ -139,12 +139,21 @@ export class ChunkGraphPlugin implements Plugin {
}
if (pageName) {
pages[pageName] = files
pageChunks[pageName] = [...involvedChunks]
if (
pageName === '/_app' ||
pageName === '/_error' ||
pageName === '/_document'
) {
sharedFiles.push(...files)
sharedChunks.push(...involvedChunks)
} else {
pages[pageName] = files
pageChunks[pageName] = [...involvedChunks]
}
} else {
if (chunk.name === CLIENT_STATIC_FILES_RUNTIME_MAIN) {
clientRuntime = files
clientRuntimeChunks = [...involvedChunks]
sharedFiles.push(...files)
sharedChunks.push(...involvedChunks)
} else {
manifest.chunks[chunk.name] = files
}
......@@ -152,7 +161,7 @@ export class ChunkGraphPlugin implements Plugin {
})
for (const page in pages) {
manifest.pages[page] = [...pages[page], ...clientRuntime]
manifest.pages[page] = [...pages[page], ...sharedFiles]
manifest.pageChunks[page] = [
...new Set([
...pageChunks[page],
......@@ -163,7 +172,7 @@ export class ChunkGraphPlugin implements Plugin {
.replace(/[.]js$/, `.${this.buildId}.js`)
: name
),
...clientRuntimeChunks,
...sharedChunks,
]),
].sort()
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment