From 397aed815e35075a6128a9f4e83d1ac36e6974b9 Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Wed, 5 Feb 2025 16:40:56 -0800 Subject: [PATCH] Use emitAsset --- .../webpack/plugins/build-manifest-plugin.ts | 44 ++++++++++--------- .../webpack/plugins/pages-manifest-plugin.ts | 42 ++++++++++-------- 2 files changed, 47 insertions(+), 39 deletions(-) diff --git a/packages/next/src/build/webpack/plugins/build-manifest-plugin.ts b/packages/next/src/build/webpack/plugins/build-manifest-plugin.ts index 51d6422a4defd..167097e437547 100644 --- a/packages/next/src/build/webpack/plugins/build-manifest-plugin.ts +++ b/packages/next/src/build/webpack/plugins/build-manifest-plugin.ts @@ -201,7 +201,7 @@ export default class BuildManifestPlugin { this.rewrites.fallback = options.rewrites.fallback.map(processRoute) } - createAssets(compiler: any, compilation: any, assets: any) { + createAssets(compiler: any, compilation: any) { const compilationSpan = spans.get(compilation) || spans.get(compiler) const createAssetsSpan = ( compilationSpan || new Span({ name: '' }) @@ -299,7 +299,10 @@ export default class BuildManifestPlugin { this.buildId ) assetMap.lowPriorityFiles.push(buildManifestPath, ssgManifestPath) - assets[ssgManifestPath] = new sources.RawSource(srcEmptySsgManifest) + compilation.emitAsset( + ssgManifestPath, + new sources.RawSource(srcEmptySsgManifest) + ) } assetMap.pages = Object.keys(assetMap.pages) @@ -316,29 +319,30 @@ export default class BuildManifestPlugin { buildManifestName = `fallback-${BUILD_MANIFEST}` } - assets[buildManifestName] = new sources.RawSource( - JSON.stringify(assetMap, null, 2) + compilation.emitAsset( + buildManifestName, + new sources.RawSource(JSON.stringify(assetMap, null, 2)) ) - assets[`server/${MIDDLEWARE_BUILD_MANIFEST}.js`] = new sources.RawSource( - `${createEdgeRuntimeManifest(assetMap)}` + compilation.emitAsset( + `server/${MIDDLEWARE_BUILD_MANIFEST}.js`, + new sources.RawSource(`${createEdgeRuntimeManifest(assetMap)}`) ) if (!this.isDevFallback) { - const clientManifestPath = `${CLIENT_STATIC_FILES_PATH}/${this.buildId}/_buildManifest.js` - - assets[clientManifestPath] = new sources.RawSource( - `self.__BUILD_MANIFEST = ${generateClientManifest( - assetMap, - this.rewrites, - this.clientRouterFilters, - compiler, - compilation - )};self.__BUILD_MANIFEST_CB && self.__BUILD_MANIFEST_CB()` + compilation.emitAsset( + `${CLIENT_STATIC_FILES_PATH}/${this.buildId}/_buildManifest.js`, + new sources.RawSource( + `self.__BUILD_MANIFEST = ${generateClientManifest( + assetMap, + this.rewrites, + this.clientRouterFilters, + compiler, + compilation + )};self.__BUILD_MANIFEST_CB && self.__BUILD_MANIFEST_CB()` + ) ) } - - return assets }) } @@ -349,8 +353,8 @@ export default class BuildManifestPlugin { name: 'NextJsBuildManifest', stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS, }, - (assets: any) => { - this.createAssets(compiler, compilation, assets) + () => { + this.createAssets(compiler, compilation) } ) }) diff --git a/packages/next/src/build/webpack/plugins/pages-manifest-plugin.ts b/packages/next/src/build/webpack/plugins/pages-manifest-plugin.ts index 09be591ac4011..b09d104fbe283 100644 --- a/packages/next/src/build/webpack/plugins/pages-manifest-plugin.ts +++ b/packages/next/src/build/webpack/plugins/pages-manifest-plugin.ts @@ -134,14 +134,17 @@ export default class PagesManifestPlugin } else { const pagesManifestPath = (!this.dev && !this.isEdgeRuntime ? '../' : '') + PAGES_MANIFEST - assets[pagesManifestPath] = new sources.RawSource( - JSON.stringify( - { - ...edgeServerPages, - ...nodeServerPages, - }, - null, - 2 + compilation.emitAsset( + pagesManifestPath, + new sources.RawSource( + JSON.stringify( + { + ...edgeServerPages, + ...nodeServerPages, + }, + null, + 2 + ) ) ) } @@ -158,16 +161,17 @@ export default class PagesManifestPlugin ...nodeServerAppPaths, }) } else { - assets[ - (!this.dev && !this.isEdgeRuntime ? '../' : '') + APP_PATHS_MANIFEST - ] = new sources.RawSource( - JSON.stringify( - { - ...edgeServerAppPaths, - ...nodeServerAppPaths, - }, - null, - 2 + compilation.emitAsset( + (!this.dev && !this.isEdgeRuntime ? '../' : '') + APP_PATHS_MANIFEST, + new sources.RawSource( + JSON.stringify( + { + ...edgeServerAppPaths, + ...nodeServerAppPaths, + }, + null, + 2 + ) ) ) } @@ -181,7 +185,7 @@ export default class PagesManifestPlugin name: 'NextJsPagesManifest', stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS, }, - (assets) => this.createAssets(compilation, assets) + () => this.createAssets(compilation) ) }) }