@@ -7,7 +7,7 @@ import MagicString from 'magic-string'
7
7
import { preProcessCSS } from './runtime/pre-process-css'
8
8
import { getVBindVariableListByPath } from './runtime/process-css'
9
9
import { initOption } from './option'
10
- import { getVariable , matchVariable } from './parser'
10
+ import { getVariable , matchVariable , parserCompiledSfc } from './parser'
11
11
import {
12
12
injectCSSVars ,
13
13
injectCssOnBuild ,
@@ -59,6 +59,7 @@ const unplugin = createUnplugin<Options>(
59
59
} = getVBindVariableListByPath ( descriptor , id , CSSFileModuleMap , isServer , userOptions . alias )
60
60
const variableName = getVariable ( descriptor )
61
61
vbindVariableList . set ( id , matchVariable ( vbindVariableListByPath , variableName ) )
62
+
62
63
// TODO: webpack
63
64
// 'vite' | 'rollup' | 'esbuild'
64
65
if ( ! isServer && framework !== 'webpack' && framework !== 'rspack' )
@@ -82,11 +83,13 @@ const unplugin = createUnplugin<Options>(
82
83
vite : {
83
84
// Vite plugin
84
85
configResolved ( config : ResolvedConfig ) {
86
+ // TODO
85
87
if ( userOptions . server !== undefined )
86
88
isServer = userOptions . server
87
89
else
88
90
isServer = config . command === 'serve'
89
91
} ,
92
+ // TODO
90
93
handleHotUpdate ( hmr : HmrContext ) {
91
94
if ( SUPPORT_FILE_REG . test ( hmr . file ) ) {
92
95
isHmring = true
@@ -114,15 +117,16 @@ const unplugin = createUnplugin<Options>(
114
117
// 'vite' | 'rollup' | 'esbuild'
115
118
if ( isServer ) {
116
119
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)
119
123
injectRes . vbindVariableList && vbindVariableList . set ( id , injectRes . vbindVariableList )
120
124
isHmring = false
121
125
}
122
126
123
- if ( framework === 'vite' ||
124
- framework === 'rollup' ||
125
- framework === 'esbuild' ) {
127
+ if ( framework === 'vite'
128
+ || framework === 'rollup'
129
+ || framework === 'esbuild' ) {
126
130
if ( id . endsWith ( '.vue' ) )
127
131
injectCSSVarsFn ( id )
128
132
@@ -135,10 +139,11 @@ const unplugin = createUnplugin<Options>(
135
139
}
136
140
}
137
141
142
+ // TODO webpack
138
143
if ( framework === 'webpack' ) {
139
144
if ( id . includes ( 'vue&type=script' ) ) {
140
145
const transId = id . split ( '?vue&type=script' ) [ 0 ]
141
- // todo 重复注入了
146
+ // TODO 重复注入了
142
147
injectCSSVarsFn ( transId )
143
148
}
144
149
const cssFMM = CSSFileModuleMap . get ( id )
0 commit comments