From 0f9bcbf68f0a793fc94b97be6d21525a72cfb4ff Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 8 Feb 2022 00:10:42 +0000 Subject: [PATCH] fix(vite): invalidate client modules too (#3116) --- packages/vite/src/server.ts | 10 +--------- packages/vite/src/vite.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/vite/src/server.ts b/packages/vite/src/server.ts index 249647f243..508434a578 100644 --- a/packages/vite/src/server.ts +++ b/packages/vite/src/server.ts @@ -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()) diff --git a/packages/vite/src/vite.ts b/packages/vite/src/vite.ts index 10b59d549e..8af080ce8d 100644 --- a/packages/vite/src/vite.ts +++ b/packages/vite/src/vite.ts @@ -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`)