@@ -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 ) {
0 commit comments