fix(vite): add back invalidateModule call

this reverts commit b765251ce8
This commit is contained in:
Daniel Roe 2025-01-21 13:36:37 +00:00
parent 1ea4fafe1a
commit 5ab0e73d8a
No known key found for this signature in database
GPG Key ID: 3714AB03996F442B

View File

@ -212,12 +212,13 @@ export const bundle: NuxtBuilder['bundle'] = async (nuxt) => {
nuxt.hook('vite:serverCreated', (server: vite.ViteDevServer, env) => { nuxt.hook('vite:serverCreated', (server: vite.ViteDevServer, env) => {
// Invalidate virtual modules when templates are re-generated // Invalidate virtual modules when templates are re-generated
ctx.nuxt.hook('app:templatesGenerated', (_app, changedTemplates) => { ctx.nuxt.hook('app:templatesGenerated', async (_app, changedTemplates) => {
for (const template of changedTemplates) { await Promise.all(changedTemplates.map(async (template) => {
for (const mod of server.moduleGraph.getModulesByFile(`virtual:nuxt:${encodeURIComponent(template.dst)}`) || []) { 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) { if (nuxt.options.vite.warmupEntry !== false) {