perf(nuxt): allow tree-shaking empty meta from build (#19032)

This commit is contained in:
Daniel Roe 2023-02-14 22:22:53 +00:00 committed by GitHub
parent 523b495e1d
commit 59a1f7bae0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -16,7 +16,7 @@ export interface PageMetaPluginOptions {
}
const CODE_EMPTY = `
const __nuxt_page_meta = {}
const __nuxt_page_meta = null
export default __nuxt_page_meta
`
@ -138,7 +138,7 @@ export const PageMetaPlugin = createUnplugin((options: PageMetaPluginOptions) =>
const meta = node.arguments[0] as Expression & { start: number, end: number }
let contents = `const __nuxt_page_meta = ${code!.slice(meta.start, meta.end) || '{}'}\nexport default __nuxt_page_meta` + (options.dev ? CODE_HMR : '')
let contents = `const __nuxt_page_meta = ${code!.slice(meta.start, meta.end) || 'null'}\nexport default __nuxt_page_meta` + (options.dev ? CODE_HMR : '')
function addImport (name: string | false) {
if (name && importMap.has(name)) {

View File

@ -264,7 +264,7 @@ export function normalizeRoutes (routes: NuxtPage[], metaImports: Set<string> =
name: `${metaImportName}?.name ?? ${page.name ? JSON.stringify(page.name) : 'undefined'}`,
path: `${metaImportName}?.path ?? ${JSON.stringify(page.path)}`,
children: page.children ? normalizeRoutes(page.children, metaImports).routes : [],
meta: page.meta ? `{...(${metaImportName} || {}), ...${JSON.stringify(page.meta)}}` : metaImportName,
meta: page.meta ? `{...(${metaImportName} || {}), ...${JSON.stringify(page.meta)}}` : `${metaImportName} || {}`,
alias: aliasCode,
redirect: page.redirect ? JSON.stringify(page.redirect) : `${metaImportName}?.redirect || undefined`,
component: genDynamicImport(file, { interopDefault: true })