mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-31 15:50:32 +00:00
perf(nuxt): allow tree-shaking empty meta from build (#19032)
This commit is contained in:
parent
523b495e1d
commit
59a1f7bae0
@ -16,7 +16,7 @@ export interface PageMetaPluginOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const CODE_EMPTY = `
|
const CODE_EMPTY = `
|
||||||
const __nuxt_page_meta = {}
|
const __nuxt_page_meta = null
|
||||||
export default __nuxt_page_meta
|
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 }
|
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) {
|
function addImport (name: string | false) {
|
||||||
if (name && importMap.has(name)) {
|
if (name && importMap.has(name)) {
|
||||||
|
@ -264,7 +264,7 @@ export function normalizeRoutes (routes: NuxtPage[], metaImports: Set<string> =
|
|||||||
name: `${metaImportName}?.name ?? ${page.name ? JSON.stringify(page.name) : 'undefined'}`,
|
name: `${metaImportName}?.name ?? ${page.name ? JSON.stringify(page.name) : 'undefined'}`,
|
||||||
path: `${metaImportName}?.path ?? ${JSON.stringify(page.path)}`,
|
path: `${metaImportName}?.path ?? ${JSON.stringify(page.path)}`,
|
||||||
children: page.children ? normalizeRoutes(page.children, metaImports).routes : [],
|
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,
|
alias: aliasCode,
|
||||||
redirect: page.redirect ? JSON.stringify(page.redirect) : `${metaImportName}?.redirect || undefined`,
|
redirect: page.redirect ? JSON.stringify(page.redirect) : `${metaImportName}?.redirect || undefined`,
|
||||||
component: genDynamicImport(file, { interopDefault: true })
|
component: genDynamicImport(file, { interopDefault: true })
|
||||||
|
Loading…
Reference in New Issue
Block a user