feat(compiler-sfc): add vapor option to script

This commit is contained in:
三咲智子 Kevin Deng 2024-02-10 14:25:33 +08:00
parent 2486d991f1
commit afa7ee2fb1
No known key found for this signature in database
GPG Key ID: 69992F2250DFD93E
2 changed files with 10 additions and 1 deletions

View File

@ -124,6 +124,10 @@ export interface SFCScriptCompileOptions {
* Transform Vue SFCs into custom elements.
*/
customElement?: boolean | ((filename: string) => boolean)
/**
* Force to use of Vapor mode.
*/
vapor?: boolean
}
export interface ImportBinding {
@ -153,11 +157,12 @@ export function compileScript(
}
const ctx = new ScriptCompileContext(sfc, options)
const { script, scriptSetup, source, filename, vapor } = sfc
const { script, scriptSetup, source, filename } = sfc
const hoistStatic = options.hoistStatic !== false && !script
const scopeId = options.id ? options.id.replace(/^data-v-/, '') : ''
const scriptLang = script && script.lang
const scriptSetupLang = scriptSetup && scriptSetup.lang
const vapor = sfc.vapor || options.vapor
let refBindings: string[] | undefined
@ -920,6 +925,9 @@ export function compileScript(
: `export default`
let runtimeOptions = ``
if (vapor) {
runtimeOptions += `\n vapor: true,`
}
if (!ctx.hasDefaultExportName && filename && filename !== DEFAULT_FILENAME) {
const match = filename.match(/([^/\\]+)\.\w+$/)
if (match) {

View File

@ -96,6 +96,7 @@ const sfcOptions = computed(
inlineTemplate: productionMode.value,
isProd: productionMode.value,
propsDestructure: true,
vapor: useVaporMode.value,
},
style: {
isProd: productionMode.value,