fix(hmr): allow disabling md cache during dev (#2581)

pull/2586/head
Divyansh Singh 1 year ago committed by GitHub
parent d5ccc52048
commit f60b32f02f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -36,4 +36,5 @@ export interface MarkdownEnv {
relativePath: string
cleanUrls: boolean
links?: string[]
includes?: string[]
}

@ -50,6 +50,7 @@ export interface MarkdownOptions extends MarkdownIt.Options {
languages?: ILanguageRegistration[]
toc?: TocPluginOptions
externalLinks?: Record<string, string>
cache?: boolean
}
export type MarkdownRenderer = MarkdownIt

@ -140,15 +140,15 @@ export const snippetPlugin = (md: MarkdownIt, srcDir: string) => {
const fence = md.renderer.rules.fence!
md.renderer.rules.fence = (...args) => {
const [tokens, idx, , { loader }] = args
const [tokens, idx, , { includes }] = args
const token = tokens[idx]
// @ts-ignore
const [src, regionName] = token.src ?? []
if (!src) return fence(...args)
if (loader) {
loader.addDependency(src)
if (includes) {
includes.push(src)
}
const isAFile = fs.lstatSync(src).isFile()

@ -67,10 +67,12 @@ export async function createMarkdownToVueRenderFn(
const relativePath = slash(path.relative(srcDir, file))
const cacheKey = JSON.stringify({ src, file })
const cached = cache.get(cacheKey)
if (cached) {
debug(`[cache hit] ${relativePath}`)
return cached
if (isBuild || options.cache !== false) {
const cached = cache.get(cacheKey)
if (cached) {
debug(`[cache hit] ${relativePath}`)
return cached
}
}
const start = Date.now()
@ -125,7 +127,8 @@ export async function createMarkdownToVueRenderFn(
const env: MarkdownEnv = {
path: file,
relativePath,
cleanUrls
cleanUrls,
includes
}
const html = md.render(src, env)
const {
@ -243,7 +246,9 @@ export async function createMarkdownToVueRenderFn(
deadLinks,
includes
}
cache.set(cacheKey, result)
if (isBuild || options.cache !== false) {
cache.set(cacheKey, result)
}
return result
}
}

Loading…
Cancel
Save