mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
perf(nuxt): clear route meta build cache when pages change (#25514)
This commit is contained in:
parent
541a802fef
commit
3e5560ed42
@ -135,18 +135,25 @@ export function extractScriptContent (html: string) {
|
||||
const PAGE_META_RE = /(definePageMeta\([\s\S]*?\))/
|
||||
const DYNAMIC_META_KEY = '__nuxt_dynamic_meta_key' as const
|
||||
|
||||
const pageContentsCache: Record<string, string> = {}
|
||||
const metaCache: Record<string, Partial<Record<keyof NuxtPage, any>>> = {}
|
||||
async function getRouteMeta (contents: string, absolutePath?: string): Promise<Partial<Record<keyof NuxtPage, any>>> {
|
||||
if (contents in metaCache) { return metaCache[contents] }
|
||||
async function getRouteMeta (contents: string, absolutePath: string): Promise<Partial<Record<keyof NuxtPage, any>>> {
|
||||
// set/update pageContentsCache, invalidate metaCache on cache mismatch
|
||||
if (!(absolutePath in pageContentsCache) || pageContentsCache[absolutePath] !== contents) {
|
||||
pageContentsCache[absolutePath] = contents
|
||||
delete metaCache[absolutePath]
|
||||
}
|
||||
|
||||
if (absolutePath in metaCache) { return metaCache[absolutePath] }
|
||||
|
||||
const script = extractScriptContent(contents)
|
||||
if (!script) {
|
||||
metaCache[contents] = {}
|
||||
metaCache[absolutePath] = {}
|
||||
return {}
|
||||
}
|
||||
|
||||
if (!PAGE_META_RE.test(script)) {
|
||||
metaCache[contents] = {}
|
||||
metaCache[absolutePath] = {}
|
||||
return {}
|
||||
}
|
||||
|
||||
@ -158,7 +165,7 @@ async function getRouteMeta (contents: string, absolutePath?: string): Promise<P
|
||||
}) as unknown as Program
|
||||
const pageMetaAST = ast.body.find(node => node.type === 'ExpressionStatement' && node.expression.type === 'CallExpression' && node.expression.callee.type === 'Identifier' && node.expression.callee.name === 'definePageMeta')
|
||||
if (!pageMetaAST) {
|
||||
metaCache[contents] = {}
|
||||
metaCache[absolutePath] = {}
|
||||
return {}
|
||||
}
|
||||
|
||||
@ -221,7 +228,7 @@ async function getRouteMeta (contents: string, absolutePath?: string): Promise<P
|
||||
extractedMeta.meta[DYNAMIC_META_KEY] = dynamicProperties
|
||||
}
|
||||
|
||||
metaCache[contents] = extractedMeta
|
||||
metaCache[absolutePath] = extractedMeta
|
||||
return extractedMeta
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user