Skip to content

Commit

Permalink
Fix buildmanifest for webpack 5 splitchunks
Browse files Browse the repository at this point in the history
Fixes an edge case introduced in vercel#21208
  • Loading branch information
timneutkens committed Jan 19, 2021
1 parent 85624d6 commit 4fcbb55
Showing 1 changed file with 12 additions and 30 deletions.
42 changes: 12 additions & 30 deletions packages/next/build/webpack/plugins/build-manifest-plugin.ts
Expand Up @@ -70,17 +70,6 @@ function isJsFile(file: string): boolean {
return !file.endsWith('.hot-update.js') && file.endsWith('.js')
}

function getFilesArray(files: any) {
if (!files) {
return []
}
if (isWebpack5) {
return Array.from(files)
}

return files
}

// This plugin creates a build-manifest.json for all assets that are being output
// It has a mapping of "entry" filename to real filename. Because the real filename can be hashed in production
export default class BuildManifestPlugin {
Expand All @@ -106,8 +95,6 @@ export default class BuildManifestPlugin {
return tracer.withSpan(spans.get(compiler), () => {
const span = tracer.startSpan('NextJsBuildManifest-createassets')
return traceFn(span, () => {
const namedChunks: Map<string, webpack.compilation.Chunk> =
compilation.namedChunks
const assetMap: DeepMutable<BuildManifest> = {
polyfillFiles: [],
devFiles: [],
Expand All @@ -129,27 +116,22 @@ export default class BuildManifestPlugin {
}
}

const mainJsChunk = namedChunks.get(CLIENT_STATIC_FILES_RUNTIME_MAIN)

const mainJsFiles: string[] = getFilesArray(mainJsChunk?.files).filter(
isJsFile
)

const polyfillChunk = namedChunks.get(
CLIENT_STATIC_FILES_RUNTIME_POLYFILLS
)

const mainJsFiles = compilation.entrypoints
.get(CLIENT_STATIC_FILES_RUNTIME_MAIN)
.getFiles()
.filter(isJsFile)
// Create a separate entry for polyfills
assetMap.polyfillFiles = getFilesArray(polyfillChunk?.files).filter(
isJsFile
)
assetMap.polyfillFiles = compilation.entrypoints
.get(CLIENT_STATIC_FILES_RUNTIME_POLYFILLS)
.getFiles()
.filter(isJsFile)

const reactRefreshChunk = namedChunks.get(
const reactRefreshChunk = compilation.entrypoints.get(
CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH
)
assetMap.devFiles = getFilesArray(reactRefreshChunk?.files).filter(
isJsFile
)
assetMap.devFiles = reactRefreshChunk
? reactRefreshChunk.getFiles().filter(isJsFile)
: []

for (const entrypoint of compilation.entrypoints.values()) {
const isAmpRuntime =
Expand Down

0 comments on commit 4fcbb55

Please sign in to comment.