silverwolf-x/project / packages /next /src /build /webpack /plugins /build-manifest-plugin-utils.ts
silverwolf-x's picture
download
raw
1.7 kB
import type { CustomRoutes, Rewrite } from '../../../lib/load-custom-routes'
import type { BuildManifest } from '../../../server/get-page-files'
export type ClientBuildManifest = {
[key: string]: string[]
}
// Add the runtime ssg manifest file as a lazy-loaded file dependency.
// We also stub this file out for development mode (when it is not
// generated).
export const srcEmptySsgManifest = `self.__SSG_MANIFEST=new Set;self.__SSG_MANIFEST_CB&&self.__SSG_MANIFEST_CB()`
function normalizeRewrite(item: {
source: string
destination: string
has?: any
}): CustomRoutes['rewrites']['beforeFiles'][0] {
return {
has: item.has,
source: item.source,
destination: item.destination,
}
}
export const processRoute = (r: Rewrite) => {
const rewrite = { ...r }
// omit external rewrite destinations since these aren't
// handled client-side
if (!rewrite?.destination?.startsWith('/')) {
delete (rewrite as any).destination
}
return rewrite
}
export function normalizeRewritesForBuildManifest(
rewrites: CustomRoutes['rewrites']
): CustomRoutes['rewrites'] {
return {
afterFiles: rewrites.afterFiles
?.map(processRoute)
?.map((item) => normalizeRewrite(item)),
beforeFiles: rewrites.beforeFiles
?.map(processRoute)
?.map((item) => normalizeRewrite(item)),
fallback: rewrites.fallback
?.map(processRoute)
?.map((item) => normalizeRewrite(item)),
}
}
export function createEdgeRuntimeManifest(
assetMap: Partial<BuildManifest>
): string {
// we use globalThis here because middleware can be node
// which doesn't have "self"
return `globalThis.__BUILD_MANIFEST = ${JSON.stringify(assetMap, null, 2)};\n`
}

Xet Storage Details

Size:
1.7 kB
·
Xet hash:
2e51efedbcca77dfab7d7379234f6cd5ad3190414575138779c6eff3823c94dd

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.