@@ -25,7 +25,9 @@ const unplugin = createUnplugin<Options>(
25
25
)
26
26
// 预处理 css 文件
27
27
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 } > ( )
29
31
let isScriptSetup = false
30
32
if ( userOptions . server === undefined ) {
31
33
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>(
50
52
injectCSSContent,
51
53
} = getVBindVariableListByPath ( descriptor , id , CSSFileModuleMap , isServer , userOptions . alias )
52
54
const variableName = getVariable ( descriptor )
53
- vbindVariableList . set ( id , matchVariable ( vbindVariableListByPath , variableName ) )
55
+ vbindVariableList . set ( id , {
56
+ TMatchVariable : matchVariable ( vbindVariableListByPath , variableName ) ,
57
+ } )
54
58
55
59
if ( ! isServer )
56
60
code = injectCssOnBuild ( code , injectCSSContent , descriptor )
@@ -68,6 +72,10 @@ const unplugin = createUnplugin<Options>(
68
72
else
69
73
isServer = config . command === 'serve'
70
74
} ,
75
+ handleHotUpdate ( hmr ) {
76
+ if ( hmr . file . endsWith ( 'foo.css' ) )
77
+ return hmr . modules
78
+ } ,
71
79
} ,
72
80
} ,
73
81
{
@@ -78,14 +86,23 @@ const unplugin = createUnplugin<Options>(
78
86
try {
79
87
// transform in dev
80
88
if ( isServer ) {
81
- console . log ( code )
82
89
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 )
84
95
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 )
86
105
}
87
- if ( id . includes ( 'type=style' ) )
88
- code = injectCssOnServer ( code , vbindVariableList . get ( id . split ( '?vue' ) [ 0 ] ) )
89
106
}
90
107
return code
91
108
} catch ( err : unknown ) {
0 commit comments