feat(nuxt): expose filtered templates in `app:templatesGenerated` hook (#21935)

This commit is contained in:
Anthony Fu 2023-07-30 19:41:01 +08:00 committed by GitHub
parent 2f734df9b5
commit c5f94be5d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View File

@ -33,8 +33,10 @@ export async function generateApp (nuxt: Nuxt, app: NuxtApp, options: { filter?:
// Compile templates into vfs
const templateContext = { utils: templateUtils, nuxt, app }
await Promise.all((app.templates as Array<ReturnType<typeof normalizeTemplate>>)
const filteredTemplates = (app.templates as Array<ReturnType<typeof normalizeTemplate>>)
.filter(template => !options.filter || options.filter(template))
await Promise.all(filteredTemplates
.map(async (template) => {
const contents = await compileTemplate(template, templateContext)
@ -55,7 +57,7 @@ export async function generateApp (nuxt: Nuxt, app: NuxtApp, options: { filter?:
}
}))
await nuxt.callHook('app:templatesGenerated', app)
await nuxt.callHook('app:templatesGenerated', app, filteredTemplates, options)
}
async function resolveApp (nuxt: Nuxt, app: NuxtApp) {

View File

@ -123,7 +123,7 @@ export interface NuxtHooks {
* @param app The configured `NuxtApp` object
* @returns Promise
*/
'app:templatesGenerated': (app: NuxtApp) => HookResult
'app:templatesGenerated': (app: NuxtApp, templates: ResolvedNuxtTemplate[], options?: GenerateAppOptions) => HookResult
/**
* Called before Nuxt bundle builder.