Skip to content

Commit 05a8bef

Browse files
committed
fix: Ignore jsx and tsx parsing(close:#47 )
1 parent 4399659 commit 05a8bef

File tree

6 files changed

+443
-10
lines changed

6 files changed

+443
-10
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@
106106
"@unplugin-vue-cssvars/entry": "workspace:*",
107107
"@unplugin-vue-cssvars/play": "workspace:*",
108108
"@unplugin-vue-cssvars/utils": "workspace:*",
109-
"@vitejs/plugin-vue": "^4.0.0",
109+
"@vitejs/plugin-vue": "^4.1.0",
110+
"@vitejs/plugin-vue-jsx": "^3.0.1",
110111
"@vitest/coverage-c8": "^0.30.1",
111112
"@vitest/ui": "^0.30.1",
112113
"@vue/compiler-sfc": "^3.2.47",

packages/core/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createUnplugin } from 'unplugin'
2-
import { NAME, SUPPORT_FILE_REG } from '@unplugin-vue-cssvars/utils'
2+
import { JSX_TSX_REG, NAME, SUPPORT_FILE_REG } from '@unplugin-vue-cssvars/utils'
33
import { createFilter } from '@rollup/pluginutils'
44
import { parse } from '@vue/compiler-sfc'
55
import chalk from 'chalk'
@@ -47,6 +47,11 @@ const unplugin = createUnplugin<Options>(
4747
// ⭐TODO: 只支持 .vue ? jsx, tsx, js, ts ?
4848
if (id.endsWith('.vue')) {
4949
const { descriptor } = parse(code)
50+
const lang = descriptor?.script?.lang ?? 'js'
51+
// ⭐TODO: 只支持 .vue ? jsx, tsx, js, ts ?
52+
if (JSX_TSX_REG.test(`.${lang}`))
53+
return code
54+
5055
isScriptSetup = !!descriptor.scriptSetup
5156
const {
5257
vbindVariableListByPath,

play/src/comp.vue

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<script setup lang="ts">
2-
import { reactive, ref } from 'vue'
1+
<script lang="tsx">
2+
/* import { reactive, ref } from 'vue'
33
const compAsd = () => 'red'
44
const color = 'red'
55
const compTheme1 = compAsd()
@@ -8,7 +8,13 @@ const sassColor = 'pink'
88
const compTheme3 = ref('red')
99
const compTheme4 = reactive({ color: 'red' })
1010
const compTheme5 = { color: 'red' }
11-
const compTheme6 = () => 'red'
11+
const compTheme6 = () => 'red' */
12+
import { defineComponent } from 'vue'
13+
export default defineComponent({
14+
setup() {
15+
return () => (<div>test</div>)
16+
},
17+
})
1218
</script>
1319

1420
<template>

play/vite.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { resolve } from 'path'
22
import { defineConfig } from 'vite'
33
import vue from '@vitejs/plugin-vue'
4+
import vueJsx from '@vitejs/plugin-vue-jsx'
45
import { viteVueCSSVars } from '../dist'
56
// https://vitejs.dev/config/
67
export default defineConfig({
@@ -32,13 +33,13 @@ export default defineConfig({
3233
},
3334
plugins: [
3435
vue(),
36+
vueJsx(),
3537
viteVueCSSVars({
3638
include: [/.vue/],
3739
includeCompile: ['**/**.scss', '**/**.css'],
3840
alias: {
3941
'@': resolve(__dirname, './src'),
4042
},
41-
server: true,
4243
}),
4344
],
4445
})

0 commit comments

Comments
 (0)