Skip to content

Commit f60b32f

Browse files
authored
fix(hmr): allow disabling md cache during dev (#2581)
1 parent d5ccc52 commit f60b32f

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

src/node/markdown/env.ts

+1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ export interface MarkdownEnv {
3636
relativePath: string
3737
cleanUrls: boolean
3838
links?: string[]
39+
includes?: string[]
3940
}

src/node/markdown/markdown.ts

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export interface MarkdownOptions extends MarkdownIt.Options {
5050
languages?: ILanguageRegistration[]
5151
toc?: TocPluginOptions
5252
externalLinks?: Record<string, string>
53+
cache?: boolean
5354
}
5455

5556
export type MarkdownRenderer = MarkdownIt

src/node/markdown/plugins/snippet.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,15 @@ export const snippetPlugin = (md: MarkdownIt, srcDir: string) => {
140140
const fence = md.renderer.rules.fence!
141141

142142
md.renderer.rules.fence = (...args) => {
143-
const [tokens, idx, , { loader }] = args
143+
const [tokens, idx, , { includes }] = args
144144
const token = tokens[idx]
145145
// @ts-ignore
146146
const [src, regionName] = token.src ?? []
147147

148148
if (!src) return fence(...args)
149149

150-
if (loader) {
151-
loader.addDependency(src)
150+
if (includes) {
151+
includes.push(src)
152152
}
153153

154154
const isAFile = fs.lstatSync(src).isFile()

src/node/markdownToVue.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,12 @@ export async function createMarkdownToVueRenderFn(
6767
const relativePath = slash(path.relative(srcDir, file))
6868
const cacheKey = JSON.stringify({ src, file })
6969

70-
const cached = cache.get(cacheKey)
71-
if (cached) {
72-
debug(`[cache hit] ${relativePath}`)
73-
return cached
70+
if (isBuild || options.cache !== false) {
71+
const cached = cache.get(cacheKey)
72+
if (cached) {
73+
debug(`[cache hit] ${relativePath}`)
74+
return cached
75+
}
7476
}
7577

7678
const start = Date.now()
@@ -125,7 +127,8 @@ export async function createMarkdownToVueRenderFn(
125127
const env: MarkdownEnv = {
126128
path: file,
127129
relativePath,
128-
cleanUrls
130+
cleanUrls,
131+
includes
129132
}
130133
const html = md.render(src, env)
131134
const {
@@ -243,7 +246,9 @@ export async function createMarkdownToVueRenderFn(
243246
deadLinks,
244247
includes
245248
}
246-
cache.set(cacheKey, result)
249+
if (isBuild || options.cache !== false) {
250+
cache.set(cacheKey, result)
251+
}
247252
return result
248253
}
249254
}

0 commit comments

Comments
 (0)