@@ -48,6 +48,7 @@ const unplugin = createUnplugin<Options>(
48
48
try {
49
49
// ⭐TODO: 只支持 .vue ? jsx, tsx, js, ts ?
50
50
// webpack 时 使用 id.includes('vue&type=style') 判断
51
+ // webpack dev 和 build 都回进入这里
51
52
if ( id . endsWith ( '.vue' )
52
53
|| ( id . includes ( 'vue&type=style' ) && framework === 'webpack' ) ) {
53
54
const { descriptor } = parse ( code )
@@ -62,7 +63,8 @@ const unplugin = createUnplugin<Options>(
62
63
const variableName = getVariable ( descriptor )
63
64
vbindVariableList . set ( id , matchVariable ( vbindVariableListByPath , variableName ) )
64
65
65
- if ( ! isServer )
66
+ // vite、rollup、esbuild 打包生效
67
+ if ( ! isServer && framework === 'webpack' && framework === 'rspack' )
66
68
mgcStr = injectCssOnBuild ( mgcStr , injectCSSContent , descriptor )
67
69
}
68
70
}
@@ -112,17 +114,17 @@ const unplugin = createUnplugin<Options>(
112
114
let mgcStr = new MagicString ( code )
113
115
// ⭐TODO: 只支持 .vue ? jsx, tsx, js, ts ?
114
116
try {
117
+ function injectCSSVarsFn ( idKey : string ) {
118
+ const parseRes = parserCompiledSfc ( code )
119
+ const injectRes = injectCSSVars ( vbindVariableList . get ( idKey ) , isScriptSetup , parseRes , mgcStr )
120
+ mgcStr = injectRes . mgcStr
121
+ injectRes . vbindVariableList && vbindVariableList . set ( id , injectRes . vbindVariableList )
122
+ isHmring = false
123
+ }
124
+
115
125
// transform in dev
116
126
// 'vite' | 'rollup' | 'esbuild'
117
127
if ( isServer ) {
118
- function injectCSSVarsFn ( idKey : string ) {
119
- const parseRes = parserCompiledSfc ( code )
120
- const injectRes = injectCSSVars ( vbindVariableList . get ( idKey ) , isScriptSetup , parseRes , mgcStr )
121
- mgcStr = injectRes . mgcStr
122
- injectRes . vbindVariableList && vbindVariableList . set ( id , injectRes . vbindVariableList )
123
- isHmring = false
124
- }
125
-
126
128
if ( framework === 'vite'
127
129
|| framework === 'rollup'
128
130
|| framework === 'esbuild' ) {
@@ -137,19 +139,26 @@ const unplugin = createUnplugin<Options>(
137
139
)
138
140
}
139
141
}
142
+ }
140
143
141
- if ( framework === 'webpack' ) {
142
- if ( id . includes ( 'vue&type=script' ) ) {
143
- const transId = id . split ( '?vue&type=script' ) [ 0 ]
144
- injectCSSVarsFn ( transId )
145
- }
146
- const cssFMM = CSSFileModuleMap . get ( id )
147
- if ( cssFMM && cssFMM . sfcPath && cssFMM . sfcPath . size > 0 ) {
148
- const sfcPathIdList = setTArray ( cssFMM . sfcPath )
149
- sfcPathIdList . forEach ( ( v ) => {
150
- mgcStr = injectCssOnServer ( mgcStr , vbindVariableList . get ( v ) , isHmring )
151
- } )
152
- }
144
+ // webpack dev 和 build 都回进入这里
145
+ if ( framework === 'webpack' ) {
146
+ const { _module } = this
147
+
148
+ // 判断是否是热更新引起的执行
149
+ const isHotUpdate = _module && _module . hot && _module . hot . data
150
+ console . log ( isHotUpdate )
151
+
152
+ if ( id . includes ( 'vue&type=script' ) ) {
153
+ const transId = id . split ( '?vue&type=script' ) [ 0 ]
154
+ injectCSSVarsFn ( transId )
155
+ }
156
+ const cssFMM = CSSFileModuleMap . get ( id )
157
+ if ( cssFMM && cssFMM . sfcPath && cssFMM . sfcPath . size > 0 ) {
158
+ const sfcPathIdList = setTArray ( cssFMM . sfcPath )
159
+ sfcPathIdList . forEach ( ( v ) => {
160
+ mgcStr = injectCssOnServer ( mgcStr , vbindVariableList . get ( v ) , isHmring )
161
+ } )
153
162
}
154
163
}
155
164
0 commit comments