Unverified Commit bbfc0f82 authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Add more chunk graph data (#6911)

* Fix nested position

* Drop front commit

* Emit new page chunks key with all involved files for a page
parent 54d5d7aa
......@@ -277,7 +277,7 @@ export default function getBaseWebpackConfig (dir: string, {dev = false, debug =
!isServer && new ReactLoadablePlugin({
filename: REACT_LOADABLE_MANIFEST
}),
!isServer && __selectivePageBuilding && new ChunkGraphPlugin(path.resolve(dir), { filename: CHUNK_GRAPH_MANIFEST }),
!isServer && __selectivePageBuilding && new ChunkGraphPlugin(buildId, path.resolve(dir), { filename: CHUNK_GRAPH_MANIFEST }),
...(dev ? (() => {
// Even though require.cache is server only we have to clear assets from both compilations
// This is because the client compilation generates the build manifest that's used on the server side
......
......@@ -47,10 +47,16 @@ function getFiles(dir: string, modules: any[]): string[] {
}
export class ChunkGraphPlugin implements Plugin {
private buildId: string
private dir: string
private filename: string
constructor(dir: string, { filename }: { filename?: string } = {}) {
constructor(
buildId: string,
dir: string,
{ filename }: { filename?: string } = {}
) {
this.buildId = buildId
this.dir = dir
this.filename = filename || 'chunk-graph-manifest.json'
}
......@@ -61,16 +67,20 @@ export class ChunkGraphPlugin implements Plugin {
type StringDictionary = { [pageName: string]: string[] }
const manifest: {
pages: StringDictionary
pageChunks: StringDictionary
chunks: StringDictionary
hashes: StringDictionary
} = {
pages: {},
pageChunks: {},
chunks: {},
hashes: {},
}
let clientRuntime = [] as string[]
let clientRuntimeChunks = [] as string[]
const pages: StringDictionary = {}
const pageChunks: StringDictionary = {}
const allFiles = new Set()
compilation.chunks.forEach(chunk => {
......@@ -83,8 +93,11 @@ export class ChunkGraphPlugin implements Plugin {
const queue = new Set<any>(chunk.groupsIterable)
const chunksProcessed = new Set<any>()
const involvedChunks = new Set<string>()
for (const chunkGroup of queue) {
for (const chunk of chunkGroup.chunks) {
chunk.files.forEach((file: string) => involvedChunks.add(file))
if (!chunksProcessed.has(chunk)) {
chunksProcessed.add(chunk)
for (const m of chunk.modulesIterable) {
......@@ -127,19 +140,34 @@ export class ChunkGraphPlugin implements Plugin {
if (pageName) {
pages[pageName] = files
pageChunks[pageName] = [...involvedChunks]
} else {
if (chunk.name === CLIENT_STATIC_FILES_RUNTIME_MAIN) {
clientRuntime = files
clientRuntimeChunks = [...involvedChunks]
} else {
manifest.chunks[chunk.name] = files
}
}
for (const page in pages) {
manifest.pages[page] = [...pages[page], ...clientRuntime]
}
})
for (const page in pages) {
manifest.pages[page] = [...pages[page], ...clientRuntime]
manifest.pageChunks[page] = [
...new Set([
...pageChunks[page],
...pageChunks[page].map(name =>
name.includes(this.buildId)
? name
.replace(new RegExp(`${this.buildId}[\\/\\\\]`), '')
.replace(/[.]js$/, `.${this.buildId}.js`)
: name
),
...clientRuntimeChunks,
]),
].sort()
}
manifest.hashes = ([...allFiles] as string[]).sort().reduce(
(acc, cur) =>
Object.assign(
......
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