Skip to content

Commit 5050a66

Browse files
committed
fix: make it work when a default lang was specified
1 parent 4b02b6c commit 5050a66

File tree

7 files changed

+29
-3
lines changed

7 files changed

+29
-3
lines changed

packages/plugin-vue/src/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ async function genTemplateCode(
264264
// If the template is not using pre-processor AND is not using external src,
265265
// compile and inline it directly in the main module. When served in vite this
266266
// saves an extra request per SFC which can improve load performance.
267-
if (!template.lang && !template.src) {
267+
if ((!template.lang || template.lang === 'html') && !template.src) {
268268
return transformTemplateInMain(
269269
template.content,
270270
descriptor,

packages/plugin-vue/src/script.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export function canInlineMain(
105105
return false
106106
}
107107
const lang = descriptor.script?.lang || descriptor.scriptSetup?.lang
108-
if (!lang) {
108+
if (!lang || lang === 'js') {
109109
return true
110110
}
111111
if ((lang === 'ts' || lang === 'tsx') && options.devServer) {

packages/plugin-vue/src/template.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export function resolveTemplateCompilerOptions(
175175
ssr,
176176
ssrCssVars: cssVars,
177177
transformAssetUrls,
178-
preprocessLang: block.lang,
178+
preprocessLang: block.lang === 'html' ? undefined : block.lang,
179179
preprocessOptions,
180180
compilerOptions: {
181181
...options.template?.compilerOptions,

playground/vue/DefaultLangs.vue

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<template lang="html">
2+
<h2>default langs</h2>
3+
<div>
4+
default lang: <span class="default-langs">{{ foo }}</span>
5+
</div>
6+
</template>
7+
8+
<script setup lang="js">
9+
const foo = 'foo'
10+
</script>
11+
12+
<style scoped lang="css">
13+
.default-langs {
14+
color: blue;
15+
}
16+
</style>

playground/vue/Main.vue

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<SetupImportTemplate />
2828
<WorkerTest />
2929
<Url />
30+
<DefaultLangs />
3031
</template>
3132

3233
<script setup lang="ts">
@@ -49,6 +50,7 @@ import WorkerTest from './worker.vue'
4950
import { ref } from 'vue'
5051
import Url from './Url.vue'
5152
import TypeProps from './TypeProps.vue'
53+
import DefaultLangs from './DefaultLangs.vue'
5254
5355
const time = ref('loading...')
5456

playground/vue/__tests__/vue.spec.ts

+7
Original file line numberDiff line numberDiff line change
@@ -323,3 +323,10 @@ describe('macro imported types', () => {
323323
)
324324
})
325325
})
326+
327+
describe('default langs', () => {
328+
test('should work', async () => {
329+
expect(await page.textContent('.default-langs')).toBe('foo')
330+
expect(await getColor('.default-langs')).toBe('blue')
331+
})
332+
})

playground/vue/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// esbuild transpile should ignore this
44
"target": "ES5",
55
"jsx": "preserve",
6+
"allowJs": true,
67
"paths": {
78
"~utils": ["../test-utils.ts"],
89
"~types": ["./types-aliased.d.ts"]

0 commit comments

Comments
 (0)