Skip to content

Commit ff68ed3

Browse files
authoredAug 11, 2023
fix: make it work when a default lang was specified (#223)
Co-authored-by: sapphi-red <green@sapphi.red> Fixes #17
1 parent 1e8d16e commit ff68ed3

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' && options.devServer) {

‎packages/plugin-vue/src/template.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export function resolveTemplateCompilerOptions(
176176
ssr,
177177
ssrCssVars: cssVars,
178178
transformAssetUrls,
179-
preprocessLang: block.lang,
179+
preprocessLang: block.lang === 'html' ? undefined : block.lang,
180180
preprocessOptions,
181181
compilerOptions: {
182182
...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
@@ -29,6 +29,7 @@
2929
<WorkerTest />
3030
<Url />
3131
<TsGeneric msg="hello" />
32+
<DefaultLangs />
3233
</template>
3334

3435
<script setup lang="ts">
@@ -52,6 +53,7 @@ import WorkerTest from './worker.vue'
5253
import { ref } from 'vue'
5354
import Url from './Url.vue'
5455
import TypeProps from './TypeProps.vue'
56+
import DefaultLangs from './DefaultLangs.vue'
5557
5658
const TsGeneric = defineAsyncComponent(() => import('./TsGeneric.vue'))
5759

‎playground/vue/__tests__/vue.spec.ts

+7
Original file line numberDiff line numberDiff line change
@@ -337,3 +337,10 @@ describe('macro imported types', () => {
337337
test('TS with generics', async () => {
338338
expect(await page.textContent('.generic')).toMatch('hello')
339339
})
340+
341+
describe('default langs', () => {
342+
test('should work', async () => {
343+
expect(await page.textContent('.default-langs')).toBe('foo')
344+
expect(await getColor('.default-langs')).toBe('blue')
345+
})
346+
})

‎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)
Please sign in to comment.