perf(nuxt): use single iteration when normalising routes (#24946)

This commit is contained in:
Michael Brevard 2023-12-29 12:17:07 +02:00 committed by GitHub
parent 34b5299412
commit e084ee7b3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -303,11 +303,12 @@ export function normalizeRoutes (routes: NuxtPage[], metaImports: Set<string> =
return { return {
imports: metaImports, imports: metaImports,
routes: genArrayFromRaw(routes.map((page) => { routes: genArrayFromRaw(routes.map((page) => {
const route = Object.fromEntries( const route: Record<Exclude<keyof NuxtPage, 'file'>, string> & { component?: string } = Object.create(null)
Object.entries(page) for (const [key, value] of Object.entries(page)) {
.filter(([key, value]) => key !== 'file' && (Array.isArray(value) ? value.length : value)) if (key !== 'file' && (Array.isArray(value) ? value.length : value)) {
.map(([key, value]) => [key, JSON.stringify(value)]) route[key as Exclude<keyof NuxtPage, 'file'>] = JSON.stringify(value)
) as Record<Exclude<keyof NuxtPage, 'file'>, string> & { component?: string } }
}
if (page.children?.length) { if (page.children?.length) {
route.children = normalizeRoutes(page.children, metaImports).routes route.children = normalizeRoutes(page.children, metaImports).routes