mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-18 01:15:58 +00:00
fix(vite): invalidate client modules too (#3116)
This commit is contained in:
parent
dabb72ed7c
commit
0f9bcbf68f
@ -131,15 +131,7 @@ export async function buildServer (ctx: ViteBuildContext) {
|
||||
|
||||
// Start development server
|
||||
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)
|
||||
}
|
||||
}
|
||||
})
|
||||
await ctx.nuxt.callHook('vite:serverCreated', viteServer)
|
||||
|
||||
// Close server on exit
|
||||
ctx.nuxt.hook('close', () => viteServer.close())
|
||||
|
@ -104,6 +104,15 @@ export async function bundle (nuxt: Nuxt) {
|
||||
await nuxt.callHook('vite:extend', ctx)
|
||||
|
||||
nuxt.hook('vite:serverCreated', (server: vite.ViteDevServer) => {
|
||||
// Invalidate virtual modules when templates are re-generated
|
||||
ctx.nuxt.hook('app:templatesGenerated', () => {
|
||||
for (const [id, mod] of server.moduleGraph.idToModuleMap) {
|
||||
if (id.startsWith('\x00virtual:')) {
|
||||
server.moduleGraph.invalidateModule(mod)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const start = Date.now()
|
||||
warmupViteServer(server, ['/entry.mjs']).then(() => {
|
||||
consola.info(`Vite warmed up in ${Date.now() - start}ms`)
|
||||
|
Loading…
Reference in New Issue
Block a user