From ff68ed34083a4ce85e1295889e95cecd3c90282b Mon Sep 17 00:00:00 2001 From: Jonas Thelemann Date: Fri, 11 Aug 2023 12:10:18 +0200 Subject: [PATCH] fix: make it work when a default lang was specified (#223) Co-authored-by: sapphi-red Fixes #17 --- packages/plugin-vue/src/main.ts | 2 +- packages/plugin-vue/src/script.ts | 2 +- packages/plugin-vue/src/template.ts | 2 +- playground/vue/DefaultLangs.vue | 16 ++++++++++++++++ playground/vue/Main.vue | 2 ++ playground/vue/__tests__/vue.spec.ts | 7 +++++++ playground/vue/tsconfig.json | 1 + 7 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 playground/vue/DefaultLangs.vue diff --git a/packages/plugin-vue/src/main.ts b/packages/plugin-vue/src/main.ts index c43886fc..be5b5610 100644 --- a/packages/plugin-vue/src/main.ts +++ b/packages/plugin-vue/src/main.ts @@ -264,7 +264,7 @@ async function genTemplateCode( // If the template is not using pre-processor AND is not using external src, // compile and inline it directly in the main module. When served in vite this // saves an extra request per SFC which can improve load performance. - if (!template.lang && !template.src) { + if ((!template.lang || template.lang === 'html') && !template.src) { return transformTemplateInMain( template.content, descriptor, diff --git a/packages/plugin-vue/src/script.ts b/packages/plugin-vue/src/script.ts index f62a31e1..f9627faf 100644 --- a/packages/plugin-vue/src/script.ts +++ b/packages/plugin-vue/src/script.ts @@ -105,7 +105,7 @@ export function canInlineMain( return false } const lang = descriptor.script?.lang || descriptor.scriptSetup?.lang - if (!lang) { + if (!lang || lang === 'js') { return true } if (lang === 'ts' && options.devServer) { diff --git a/packages/plugin-vue/src/template.ts b/packages/plugin-vue/src/template.ts index 0f9b7fb8..d3a6350d 100644 --- a/packages/plugin-vue/src/template.ts +++ b/packages/plugin-vue/src/template.ts @@ -176,7 +176,7 @@ export function resolveTemplateCompilerOptions( ssr, ssrCssVars: cssVars, transformAssetUrls, - preprocessLang: block.lang, + preprocessLang: block.lang === 'html' ? undefined : block.lang, preprocessOptions, compilerOptions: { ...options.template?.compilerOptions, diff --git a/playground/vue/DefaultLangs.vue b/playground/vue/DefaultLangs.vue new file mode 100644 index 00000000..43f022f8 --- /dev/null +++ b/playground/vue/DefaultLangs.vue @@ -0,0 +1,16 @@ + + + + + diff --git a/playground/vue/Main.vue b/playground/vue/Main.vue index b587c916..9ab11aac 100644 --- a/playground/vue/Main.vue +++ b/playground/vue/Main.vue @@ -29,6 +29,7 @@ +