@@ -7,7 +7,7 @@ import MagicString from 'magic-string'
77import { preProcessCSS } from './runtime/pre-process-css'
88import { getVBindVariableListByPath } from './runtime/process-css'
99import { initOption } from './option'
10- import { getVariable , matchVariable } from './parser'
10+ import { getVariable , matchVariable , parserCompiledSfc } from './parser'
1111import {
1212 injectCSSVars ,
1313 injectCssOnBuild ,
@@ -59,6 +59,7 @@ const unplugin = createUnplugin<Options>(
5959 } = getVBindVariableListByPath ( descriptor , id , CSSFileModuleMap , isServer , userOptions . alias )
6060 const variableName = getVariable ( descriptor )
6161 vbindVariableList . set ( id , matchVariable ( vbindVariableListByPath , variableName ) )
62+
6263 // TODO: webpack
6364 // 'vite' | 'rollup' | 'esbuild'
6465 if ( ! isServer && framework !== 'webpack' && framework !== 'rspack' )
@@ -82,11 +83,13 @@ const unplugin = createUnplugin<Options>(
8283 vite : {
8384 // Vite plugin
8485 configResolved ( config : ResolvedConfig ) {
86+ // TODO
8587 if ( userOptions . server !== undefined )
8688 isServer = userOptions . server
8789 else
8890 isServer = config . command === 'serve'
8991 } ,
92+ // TODO
9093 handleHotUpdate ( hmr : HmrContext ) {
9194 if ( SUPPORT_FILE_REG . test ( hmr . file ) ) {
9295 isHmring = true
@@ -114,15 +117,16 @@ const unplugin = createUnplugin<Options>(
114117 // 'vite' | 'rollup' | 'esbuild'
115118 if ( isServer ) {
116119 function injectCSSVarsFn ( idKey : string ) {
117- const injectRes = injectCSSVars ( code , vbindVariableList . get ( idKey ) , isScriptSetup , framework )
118- mgcStr = mgcStr . overwrite ( 0 , mgcStr . length ( ) , injectRes . code )
120+ const parseRes = parserCompiledSfc ( code )
121+ const injectRes = injectCSSVars ( vbindVariableList . get ( idKey ) , isScriptSetup , parseRes , mgcStr )
122+ mgcStr = injectRes . mgcStr // .overwrite(0, mgcStr.length(), injectRes.code)
119123 injectRes . vbindVariableList && vbindVariableList . set ( id , injectRes . vbindVariableList )
120124 isHmring = false
121125 }
122126
123- if ( framework === 'vite' ||
124- framework === 'rollup' ||
125- framework === 'esbuild' ) {
127+ if ( framework === 'vite'
128+ || framework === 'rollup'
129+ || framework === 'esbuild' ) {
126130 if ( id . endsWith ( '.vue' ) )
127131 injectCSSVarsFn ( id )
128132
@@ -135,10 +139,11 @@ const unplugin = createUnplugin<Options>(
135139 }
136140 }
137141
142+ // TODO webpack
138143 if ( framework === 'webpack' ) {
139144 if ( id . includes ( 'vue&type=script' ) ) {
140145 const transId = id . split ( '?vue&type=script' ) [ 0 ]
141- // todo 重复注入了
146+ // TODO 重复注入了
142147 injectCSSVarsFn ( transId )
143148 }
144149 const cssFMM = CSSFileModuleMap . get ( id )
0 commit comments