fix(nuxt): don't generate separate chunk for stubs (#26291)

This commit is contained in:
Daniel Roe 2024-03-15 17:07:38 -07:00 committed by GitHub
parent e272b2f2e1
commit 814859d769
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 3 deletions

View File

@ -364,6 +364,7 @@ export default defineNuxtModule({
const rule = nitro.options.routeRules[path]
if (!rule.redirect) { continue }
routes.push({
_sync: true,
path: path.replace(/\/[^/]*\*\*/, '/:pathMatch(.*)'),
file: resolve(runtimeDir, 'component-stub')
})

View File

@ -444,9 +444,16 @@ export function normalizeRoutes (routes: NuxtPage[], metaImports: Set<string> =
}
const file = normalize(page.file)
const metaImportName = genSafeVariableName(filename(file) + hash(file)) + 'Meta'
const pageImportName = genSafeVariableName(filename(file) + hash(file))
const metaImportName = pageImportName + 'Meta'
metaImports.add(genImport(`${file}?macro=true`, [{ name: 'default', as: metaImportName }]))
if (page._sync) {
metaImports.add(genImport(file, [{ name: 'default', as: pageImportName }]))
}
const pageImport = page._sync && page.mode !== 'client' ? pageImportName : genDynamicImport(file, { interopDefault: true })
const metaRoute: NormalizedRoute = {
name: `${metaImportName}?.name ?? ${route.name}`,
path: `${metaImportName}?.path ?? ${route.path}`,
@ -456,8 +463,8 @@ export function normalizeRoutes (routes: NuxtPage[], metaImports: Set<string> =
component: page.mode === 'server'
? `() => createIslandPage(${route.name})`
: page.mode === 'client'
? `() => createClientPage(${genDynamicImport(file, { interopDefault: true })})`
: genDynamicImport(file, { interopDefault: true })
? `() => createClientPage(${pageImport})`
: pageImport
}
if (page.mode === 'server') {

View File

@ -44,6 +44,8 @@ export type NuxtPage = {
* @default 'all'
*/
mode?: 'client' | 'server' | 'all'
/** @internal */
_sync?: boolean
}
export type NuxtMiddleware = {