Skip to content

Commit

Permalink
fix: invalidate module cache on unlinked
Browse files Browse the repository at this point in the history
  • Loading branch information
csr632 committed Mar 21, 2021
1 parent 938b839 commit 5ecb393
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions packages/vite/src/node/server/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,25 +165,26 @@ export async function handleFileAddUnlink(
server: ViteDevServer,
isUnlink = false
) {
const mods = server.moduleGraph.getModulesByFile(file) ?? []
const modules = [...mods]
if (isUnlink && file in server._globImporters) {
delete server._globImporters[file]
} else {
const modules = []
for (const i in server._globImporters) {
const { module, base, pattern } = server._globImporters[i]
const relative = path.relative(base, file)
if (match(relative, pattern)) {
modules.push(module)
}
}
if (modules.length > 0) {
updateModules(
getShortName(file, server.config.root),
modules,
Date.now(),
server
)
}
}
if (modules.length > 0) {
updateModules(
getShortName(file, server.config.root),
modules,
Date.now(),
server
)
}
}

Expand Down

0 comments on commit 5ecb393

Please sign in to comment.