Skip to content

Commit

Permalink
fix(plugin-vue): rewrite default after ts compiled (#3591)
Browse files Browse the repository at this point in the history
Co-authored-by: Shinigami <chrissi92@hotmail.de>
  • Loading branch information
underfin and Shinigami92 committed Jun 1, 2021
1 parent f8c045a commit b63a7a9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/plugin-vue/package.json
Expand Up @@ -29,7 +29,7 @@
},
"homepage": "https://github.com/vitejs/vite/tree/main/packages/plugin-vue#readme",
"peerDependencies": {
"@vue/compiler-sfc": "^3.0.6"
"@vue/compiler-sfc": "^3.0.8"
},
"devDependencies": {
"@rollup/pluginutils": "^4.1.0",
Expand Down
18 changes: 2 additions & 16 deletions packages/plugin-vue/src/main.ts
Expand Up @@ -225,9 +225,6 @@ async function genTemplateCode(
}
}

const exportDefaultClassRE =
/(?:(?:^|\n|;)\s*)export\s+default\s+class\s+([\w$]+)/

async function genScriptCode(
descriptor: SFCDescriptor,
options: ResolvedOptions,
Expand All @@ -247,19 +244,7 @@ async function genScriptCode(
(!script.lang || (script.lang === 'ts' && options.devServer)) &&
!script.src
) {
// TODO remove the class check logic after upgrading @vue/compiler-sfc
const classMatch = script.content.match(exportDefaultClassRE)
if (classMatch) {
scriptCode =
script.content.replace(exportDefaultClassRE, `\nclass $1`) +
`\nconst _sfc_main = ${classMatch[1]}`
if (/export\s+default/.test(scriptCode)) {
// fallback if there are still export default
scriptCode = rewriteDefault(script.content, `_sfc_main`)
}
} else {
scriptCode = rewriteDefault(script.content, `_sfc_main`)
}
scriptCode = script.content
map = script.map
if (script.lang === 'ts') {
const result = await options.devServer!.transformWithEsbuild(
Expand All @@ -271,6 +256,7 @@ async function genScriptCode(
scriptCode = result.code
map = result.map
}
scriptCode = rewriteDefault(scriptCode, `_sfc_main`)
} else {
if (script.src) {
await linkSrcToDescriptor(script.src, descriptor, pluginContext)
Expand Down

0 comments on commit b63a7a9

Please sign in to comment.