Skip to content

Commit

Permalink
Use emitAsset
Browse files Browse the repository at this point in the history
  • Loading branch information
wbinnssmith committed Feb 6, 2025
1 parent 26a3b4c commit 397aed8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 39 deletions.
44 changes: 24 additions & 20 deletions packages/next/src/build/webpack/plugins/build-manifest-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '' })
Expand Down Expand Up @@ -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)
Expand All @@ -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
})
}

Expand All @@ -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)
}
)
})
Expand Down
42 changes: 23 additions & 19 deletions packages/next/src/build/webpack/plugins/pages-manifest-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)
)
}
Expand All @@ -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
)
)
)
}
Expand All @@ -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)
)
})
}
Expand Down

0 comments on commit 397aed8

Please sign in to comment.