@@ -47,7 +47,9 @@ const unplugin = createUnplugin<Options>(
4747 let mgcStr = new MagicString ( code )
4848 try {
4949 // ⭐TODO: 只支持 .vue ? jsx, tsx, js, ts ?
50- if ( id . endsWith ( '.vue' ) ) {
50+ // webpack 时 使用 id.includes('vue&type=style') 判断
51+ if ( id . endsWith ( '.vue' )
52+ || ( id . includes ( 'vue&type=style' ) && framework === 'webpack' ) ) {
5153 const { descriptor } = parse ( code )
5254 const lang = descriptor ?. script ?. lang ?? 'js'
5355 // ⭐TODO: 只支持 .vue ? jsx, tsx, js, ts ?
@@ -60,12 +62,11 @@ const unplugin = createUnplugin<Options>(
6062 const variableName = getVariable ( descriptor )
6163 vbindVariableList . set ( id , matchVariable ( vbindVariableListByPath , variableName ) )
6264
63- // TODO: webpack
64- // 'vite' | 'rollup' | 'esbuild'
65- if ( ! isServer && framework !== 'webpack' && framework !== 'rspack' )
65+ if ( ! isServer )
6666 mgcStr = injectCssOnBuild ( mgcStr , injectCSSContent , descriptor )
6767 }
6868 }
69+
6970 return {
7071 code : mgcStr . toString ( ) ,
7172 get map ( ) {
@@ -117,7 +118,7 @@ const unplugin = createUnplugin<Options>(
117118 function injectCSSVarsFn ( idKey : string ) {
118119 const parseRes = parserCompiledSfc ( code )
119120 const injectRes = injectCSSVars ( vbindVariableList . get ( idKey ) , isScriptSetup , parseRes , mgcStr )
120- mgcStr = injectRes . mgcStr // .overwrite(0, mgcStr.length(), injectRes.code)
121+ mgcStr = injectRes . mgcStr
121122 injectRes . vbindVariableList && vbindVariableList . set ( id , injectRes . vbindVariableList )
122123 isHmring = false
123124 }
@@ -137,11 +138,9 @@ const unplugin = createUnplugin<Options>(
137138 }
138139 }
139140
140- // TODO webpack
141141 if ( framework === 'webpack' ) {
142142 if ( id . includes ( 'vue&type=script' ) ) {
143143 const transId = id . split ( '?vue&type=script' ) [ 0 ]
144- // TODO 重复注入了
145144 injectCSSVarsFn ( transId )
146145 }
147146 const cssFMM = CSSFileModuleMap . get ( id )
0 commit comments