-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.js
32 lines (27 loc) · 895 Bytes
/
template.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { compileTemplate } from 'vue/compiler-sfc';
const COMP_ID = `__sfc__`;
export const resolveTemplate = (descriptor, context) => {
if (descriptor.template && !descriptor.scriptSetup) {
const templateResult = compileTemplate({
...context.options.sfcTemplateCompilerOptions,
id: `data-v-${context.id}`,
filename: context.filename,
source: descriptor.template.content,
scoped: context.features.hasScoped,
compilerOptions: {
bindingMetadata: context.bindingMetadata,
...context.options.sfcTemplateCompilerOptions?.compilerOptions,
},
});
const templateCode = `${templateResult.code.replace(
/\nexport (function|const) (render|ssrRender)/,
`\n$1 render`
)}\n${COMP_ID}.render = render`;
return {
result: {
code: templateCode,
},
};
}
return { result: { code: '' } };
};