Skip to content

Commit 5d2f55f

Browse files
wip(vue2): cache prepossessed template
1 parent 159dea9 commit 5d2f55f

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/createVue2SFCModule.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,20 @@ export async function createSFCModule(source : string, filename : string, option
121121

122122
// Vue2 doesn't support preprocessCustomRequire, so we have to preprocess manually
123123
if (descriptor.template?.lang) {
124-
const preprocess = moduleCache[descriptor.template.lang] as any
125-
compileTemplateOptions.source = await new Promise((resolve, reject) => {
126-
preprocess.render(compileTemplateOptions.source, compileTemplateOptions.preprocessOptions, (_err : any, _res : any) => {
127-
128-
if (_err)
129-
reject(_err)
130-
else
131-
resolve(_res)
124+
const preprocess = moduleCache[descriptor.template.lang] as any;
125+
compileTemplateOptions.source = await withCache(compiledCache, [ compileTemplateOptions.source, descriptor.template.lang ], async ({ preventCache }) => {
126+
127+
return await new Promise((resolve, reject) => {
128+
preprocess.render(compileTemplateOptions.source, compileTemplateOptions.preprocessOptions, (_err : any, _res : any) => {
129+
130+
if (_err)
131+
reject(_err)
132+
else
133+
resolve(_res)
134+
})
132135
})
133-
})
136+
137+
});
134138
}
135139

136140
if ( descriptor.script ) {

0 commit comments

Comments
 (0)