mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
fix(vite): invalidate virtual modules with vite-node
(#8389)
This commit is contained in:
parent
ded71608b4
commit
4536242245
@ -17,13 +17,6 @@ import { createIsExternal } from './utils/external'
|
||||
export function viteNodePlugin (ctx: ViteBuildContext): VitePlugin {
|
||||
// Store the invalidates for the next rendering
|
||||
const invalidates = new Set<string>()
|
||||
return {
|
||||
name: 'nuxt:vite-node-server',
|
||||
enforce: 'post',
|
||||
configureServer (server) {
|
||||
server.middlewares.use('/__nuxt_vite_node__', toNodeListener(createViteNodeApp(ctx, invalidates)))
|
||||
},
|
||||
handleHotUpdate ({ file, server }) {
|
||||
function markInvalidate (mod: ModuleNode) {
|
||||
if (!mod.id) { return }
|
||||
if (invalidates.has(mod.id)) { return }
|
||||
@ -32,6 +25,22 @@ export function viteNodePlugin (ctx: ViteBuildContext): VitePlugin {
|
||||
markInvalidate(importer)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
name: 'nuxt:vite-node-server',
|
||||
enforce: 'post',
|
||||
configureServer (server) {
|
||||
server.middlewares.use('/__nuxt_vite_node__', toNodeListener(createViteNodeApp(ctx, invalidates)))
|
||||
// Invalidate all virtual modules when templates are regenerated
|
||||
ctx.nuxt.hook('app:templatesGenerated', () => {
|
||||
for (const [id, mod] of server.moduleGraph.idToModuleMap) {
|
||||
if (id.startsWith('virtual:')) {
|
||||
markInvalidate(mod)
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
handleHotUpdate ({ file, server }) {
|
||||
const mods = server.moduleGraph.getModulesByFile(file) || []
|
||||
for (const mod of mods) {
|
||||
markInvalidate(mod)
|
||||
|
Loading…
Reference in New Issue
Block a user