mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 21:55:11 +00:00
fix(vite): invalidate virtual modules when templates are regenerated (#2725)
This commit is contained in:
parent
4111038aa7
commit
4728fd545e
@ -92,6 +92,15 @@ export async function buildServer (ctx: ViteBuildContext) {
|
|||||||
const viteServer = await vite.createServer(serverConfig)
|
const viteServer = await vite.createServer(serverConfig)
|
||||||
ctx.nuxt.hook('close', () => viteServer.close())
|
ctx.nuxt.hook('close', () => viteServer.close())
|
||||||
|
|
||||||
|
// Invalidate virtual modules when templates are re-generated
|
||||||
|
ctx.nuxt.hook('app:templatesGenerated', () => {
|
||||||
|
for (const [id, mod] of viteServer.moduleGraph.idToModuleMap) {
|
||||||
|
if (id.startsWith('\x00virtual:')) {
|
||||||
|
viteServer.moduleGraph.invalidateModule(mod)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// Initialize plugins
|
// Initialize plugins
|
||||||
await viteServer.pluginContainer.buildStart({})
|
await viteServer.pluginContainer.buildStart({})
|
||||||
|
|
||||||
|
@ -101,6 +101,15 @@ export async function buildServer (ctx: ViteBuildContext) {
|
|||||||
// Start development server
|
// Start development server
|
||||||
const viteServer = await vite.createServer(serverConfig)
|
const viteServer = await vite.createServer(serverConfig)
|
||||||
|
|
||||||
|
// Invalidate virtual modules when templates are re-generated
|
||||||
|
ctx.nuxt.hook('app:templatesGenerated', () => {
|
||||||
|
for (const [id, mod] of viteServer.moduleGraph.idToModuleMap) {
|
||||||
|
if (id.startsWith('\x00virtual:')) {
|
||||||
|
viteServer.moduleGraph.invalidateModule(mod)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// Close server on exit
|
// Close server on exit
|
||||||
ctx.nuxt.hook('close', () => viteServer.close())
|
ctx.nuxt.hook('close', () => viteServer.close())
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user