diff --git a/packages/vite/src/vite.ts b/packages/vite/src/vite.ts index bc38f848ca..85290f78c0 100644 --- a/packages/vite/src/vite.ts +++ b/packages/vite/src/vite.ts @@ -212,12 +212,13 @@ export const bundle: NuxtBuilder['bundle'] = async (nuxt) => { nuxt.hook('vite:serverCreated', (server: vite.ViteDevServer, env) => { // Invalidate virtual modules when templates are re-generated - ctx.nuxt.hook('app:templatesGenerated', (_app, changedTemplates) => { - for (const template of changedTemplates) { + ctx.nuxt.hook('app:templatesGenerated', async (_app, changedTemplates) => { + await Promise.all(changedTemplates.map(async (template) => { for (const mod of server.moduleGraph.getModulesByFile(`virtual:nuxt:${encodeURIComponent(template.dst)}`) || []) { - server.reloadModule(mod) + server.moduleGraph.invalidateModule(mod) + await server.reloadModule(mod) } - } + })) }) if (nuxt.options.vite.warmupEntry !== false) {