fix hmr with rewrites

pull/4525/head
Divyansh Singh 7 months ago
parent 928e515702
commit f3972e1547

@ -31,14 +31,14 @@ export interface MarkdownCompileResult {
includes: string[] includes: string[]
} }
export function clearCache(file?: string) { export function clearCache(id?: string) {
if (!file) { if (!id) {
cache.clear() cache.clear()
return return
} }
file = JSON.stringify({ file }).slice(1) id = JSON.stringify({ id }).slice(1)
cache.find((_, key) => key.endsWith(file!) && cache.delete(key)) cache.find((_, key) => key.endsWith(id!) && cache.delete(key))
} }
export async function createMarkdownToVueRenderFn( export async function createMarkdownToVueRenderFn(
@ -83,7 +83,7 @@ export async function createMarkdownToVueRenderFn(
file = rewrites.get(file) || file file = rewrites.get(file) || file
const relativePath = slash(path.relative(srcDir, file)) const relativePath = slash(path.relative(srcDir, file))
const cacheKey = JSON.stringify({ src, file: relativePath }) const cacheKey = JSON.stringify({ src, file: relativePath, id: fileOrig })
if (isBuild || options.cache !== false) { if (isBuild || options.cache !== false) {
const cached = cache.get(cacheKey) const cached = cache.get(cacheKey)
if (cached) { if (cached) {

@ -429,7 +429,7 @@ export async function createVitePressPlugin(
return [ return [
...modules, ...modules,
...importers.map((id) => { ...importers.map((id) => {
clearCache(slash(path.relative(srcDir, id))) clearCache(id)
return this.environment.moduleGraph.getModuleById(id) return this.environment.moduleGraph.getModuleById(id)
}) })
].filter((mod) => mod !== undefined) ].filter((mod) => mod !== undefined)

Loading…
Cancel
Save