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 {
imports: metaImports,
routes: genArrayFromRaw(routes.map((page) => {
const route = Object.fromEntries(
Object.entries(page)
.filter(([key, value]) => key !== 'file' && (Array.isArray(value) ? value.length : value))
.map(([key, value]) => [key, JSON.stringify(value)])
) as Record<Exclude<keyof NuxtPage, 'file'>, string> & { component?: string }
const route: Record<Exclude<keyof NuxtPage, 'file'>, string> & { component?: string } = Object.create(null)
for (const [key, value] of Object.entries(page)) {
if (key !== 'file' && (Array.isArray(value) ? value.length : value)) {
route[key as Exclude<keyof NuxtPage, 'file'>] = JSON.stringify(value)
}
}
if (page.children?.length) {
route.children = normalizeRoutes(page.children, metaImports).routes