Skip to content

Commit dd1f124

Browse files
committed
chore: temp commit
1 parent 34e9fd3 commit dd1f124

File tree

5 files changed

+1285
-1234
lines changed

5 files changed

+1285
-1234
lines changed

packages/core/index.ts

+24-7
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ const unplugin = createUnplugin<Options>(
2525
)
2626
// 预处理 css 文件
2727
const CSSFileModuleMap = preProcessCSS(userOptions, userOptions.alias)
28-
const vbindVariableList = new Map<string, TMatchVariable>()
28+
const vbindVariableList = new Map<string, {
29+
TMatchVariable: TMatchVariable
30+
orgTransformCode?: string }>()
2931
let isScriptSetup = false
3032
if (userOptions.server === undefined) {
3133
console.warn(chalk.yellowBright.bold(`[${NAME}] The server of option is not set, you need to specify whether you are using the development server or building the project`))
@@ -50,7 +52,9 @@ const unplugin = createUnplugin<Options>(
5052
injectCSSContent,
5153
} = getVBindVariableListByPath(descriptor, id, CSSFileModuleMap, isServer, userOptions.alias)
5254
const variableName = getVariable(descriptor)
53-
vbindVariableList.set(id, matchVariable(vbindVariableListByPath, variableName))
55+
vbindVariableList.set(id, {
56+
TMatchVariable: matchVariable(vbindVariableListByPath, variableName),
57+
})
5458

5559
if (!isServer)
5660
code = injectCssOnBuild(code, injectCSSContent, descriptor)
@@ -68,6 +72,10 @@ const unplugin = createUnplugin<Options>(
6872
else
6973
isServer = config.command === 'serve'
7074
},
75+
handleHotUpdate(hmr) {
76+
if (hmr.file.endsWith('foo.css'))
77+
return hmr.modules
78+
},
7179
},
7280
},
7381
{
@@ -78,14 +86,23 @@ const unplugin = createUnplugin<Options>(
7886
try {
7987
// transform in dev
8088
if (isServer) {
81-
console.log(code)
8289
if (id.endsWith('.vue')) {
83-
const injectRes = injectCSSVars(code, vbindVariableList.get(id), isScriptSetup)
90+
const orgCode = code
91+
// console.log('########', id)
92+
code = code.replaceAll('if (!mod)', 'console.log(mod)\n if (!mod)')
93+
// console.log(code)
94+
const injectRes = injectCSSVars(code, vbindVariableList.get(id).TMatchVariable, isScriptSetup)
8495
code = injectRes.code
85-
injectRes.vbindVariableList && vbindVariableList.set(id, injectRes.vbindVariableList)
96+
injectRes.vbindVariableList && vbindVariableList.set(id, {
97+
TMatchVariable: injectRes.vbindVariableList,
98+
orgTransformCode: orgCode,
99+
})
100+
}
101+
if (id.includes('type=style')) {
102+
console.log('########', id)
103+
code = injectCssOnServer(code, vbindVariableList.get(id.split('?vue')[0]).TMatchVariable)
104+
console.log(code)
86105
}
87-
if (id.includes('type=style'))
88-
code = injectCssOnServer(code, vbindVariableList.get(id.split('?vue')[0]))
89106
}
90107
return code
91108
} catch (err: unknown) {

packages/core/parser/parser-variable.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,13 @@ export function getObjectExpressionReturnNode(node: ObjectExpression) {
175175
return res
176176
}
177177

178-
export type TMatchVariable = Array<{ has: boolean, value: string, hash?: string, isRef: boolean }>
178+
export type TMatchVariable = Array<{
179+
has: boolean
180+
value: string
181+
hash?: string
182+
isRef: boolean
183+
orgTransformCode?: string
184+
}>
179185
export function matchVariable(
180186
importCSSModule: Array<string>,
181187
variableName: VariableName,

play/src/assets/css/foo.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#foo{
22
color: v-bind-m(color);
3-
background: #94c9ff;
3+
background: #0E53C4;
44
width: 200px;
55
height: 30px;
66
}

play/src/views/app/App.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
22
import { reactive, ref } from 'vue'
33
import Comp from '../../comp.vue'
4-
const color = 'grren'
4+
const color = ref('green')
55
const appAsd = () => 'red'
66
const fooColor = appAsd()
77
const appTheme2 = 'blue'
@@ -73,7 +73,7 @@ export default defineComponent({
7373

7474
<template>
7575
<div id="foo" class="scss" @click="sassColor = 'red'">
76-
app
76+
app1
7777
<!-- <Comp /> -->
7878
</div>
7979
</template>

0 commit comments

Comments
 (0)