Skip to content

Commit ea13c7e

Browse files
committed
update loader cache strategy
1 parent 4061f9d commit ea13c7e

File tree

1 file changed

+16
-13
lines changed
  • packages/@vuepress/markdown-loader

1 file changed

+16
-13
lines changed

packages/@vuepress/markdown-loader/index.js

+16-13
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ module.exports = function (src) {
5858

5959
// observe dependency changes
6060
const observe = callback => (...args) => {
61+
const { loader } = args[3]
62+
6163
const result = {
6264
deps: [],
6365
ctxDeps: []
@@ -82,21 +84,22 @@ module.exports = function (src) {
8284

8385
const { rules } = markdown.renderer
8486
for (const name in rules) {
85-
const rule = rules[name]
86-
if (rule._cached) continue
87-
rules[name] = (tokens, index, options, env, self) => {
88-
const { _output } = tokens[index]
89-
if (typeof _output === 'string') {
90-
return _output
87+
if (rules[name]._cached) continue
88+
const rule = observe(rules[name])
89+
rules[name] = (...args) => {
90+
const token = args[0][args[1]]
91+
if (typeof token._output === 'string') {
92+
return token._output
93+
}
94+
const { deps, ctxDeps, output = '' } = rule(...args)
95+
deps.forEach(loader.addDependency)
96+
ctxDeps.forEach(loader.addContextDependency)
97+
if (deps.length + ctxDeps.length === 0) {
98+
token._output = output
9199
} else {
92-
const { deps, ctxDeps, output } = observe(rule)(tokens, index, options, env, self)
93-
deps.forEach(loader.addDependency)
94-
ctxDeps.forEach(loader.addContextDependency)
95-
if (deps.length + ctxDeps.length === 0) {
96-
tokens[index]._output = output
97-
}
98-
return output
100+
token._output = undefined
99101
}
102+
return output
100103
}
101104
rules[name]._cached = true
102105
}

0 commit comments

Comments
 (0)