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 = ...@@ -277,7 +277,7 @@ export default function getBaseWebpackConfig (dir: string, {dev = false, debug =
!isServer && new ReactLoadablePlugin({ !isServer && new ReactLoadablePlugin({
filename: REACT_LOADABLE_MANIFEST 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 ? (() => { ...(dev ? (() => {
// Even though require.cache is server only we have to clear assets from both compilations // 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 // 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[] { ...@@ -47,10 +47,16 @@ function getFiles(dir: string, modules: any[]): string[] {
} }
export class ChunkGraphPlugin implements Plugin { export class ChunkGraphPlugin implements Plugin {
private buildId: string
private dir: string private dir: string
private filename: 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.dir = dir
this.filename = filename || 'chunk-graph-manifest.json' this.filename = filename || 'chunk-graph-manifest.json'
} }
...@@ -61,16 +67,20 @@ export class ChunkGraphPlugin implements Plugin { ...@@ -61,16 +67,20 @@ export class ChunkGraphPlugin implements Plugin {
type StringDictionary = { [pageName: string]: string[] } type StringDictionary = { [pageName: string]: string[] }
const manifest: { const manifest: {
pages: StringDictionary pages: StringDictionary
pageChunks: StringDictionary
chunks: StringDictionary chunks: StringDictionary
hashes: StringDictionary hashes: StringDictionary
} = { } = {
pages: {}, pages: {},
pageChunks: {},
chunks: {}, chunks: {},
hashes: {}, hashes: {},
} }
let clientRuntime = [] as string[] let clientRuntime = [] as string[]
let clientRuntimeChunks = [] as string[]
const pages: StringDictionary = {} const pages: StringDictionary = {}
const pageChunks: StringDictionary = {}
const allFiles = new Set() const allFiles = new Set()
compilation.chunks.forEach(chunk => { compilation.chunks.forEach(chunk => {
...@@ -83,8 +93,11 @@ export class ChunkGraphPlugin implements Plugin { ...@@ -83,8 +93,11 @@ export class ChunkGraphPlugin implements Plugin {
const queue = new Set<any>(chunk.groupsIterable) const queue = new Set<any>(chunk.groupsIterable)
const chunksProcessed = new Set<any>() const chunksProcessed = new Set<any>()
const involvedChunks = new Set<string>()
for (const chunkGroup of queue) { for (const chunkGroup of queue) {
for (const chunk of chunkGroup.chunks) { for (const chunk of chunkGroup.chunks) {
chunk.files.forEach((file: string) => involvedChunks.add(file))
if (!chunksProcessed.has(chunk)) { if (!chunksProcessed.has(chunk)) {
chunksProcessed.add(chunk) chunksProcessed.add(chunk)
for (const m of chunk.modulesIterable) { for (const m of chunk.modulesIterable) {
...@@ -127,19 +140,34 @@ export class ChunkGraphPlugin implements Plugin { ...@@ -127,19 +140,34 @@ export class ChunkGraphPlugin implements Plugin {
if (pageName) { if (pageName) {
pages[pageName] = files pages[pageName] = files
pageChunks[pageName] = [...involvedChunks]
} else { } else {
if (chunk.name === CLIENT_STATIC_FILES_RUNTIME_MAIN) { if (chunk.name === CLIENT_STATIC_FILES_RUNTIME_MAIN) {
clientRuntime = files clientRuntime = files
clientRuntimeChunks = [...involvedChunks]
} else { } else {
manifest.chunks[chunk.name] = files 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( manifest.hashes = ([...allFiles] as string[]).sort().reduce(
(acc, cur) => (acc, cur) =>
Object.assign( 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