@@ -6,12 +6,13 @@ import { preProcessCSS } from './runtime/pre-process-css'
66import { getVBindVariableListByPath } from './runtime/process-css'
77import { initOption } from './option'
88import { getVariable , matchVariable } from './parser'
9- import { injectCSSVars } from './inject/inject-cssvars'
10- import { injectCssOnBuild , injectCssOnServer } from './inject/inject-css'
9+ import {
10+ injectCSSVars ,
11+ injectCssOnBuild ,
12+ injectCssOnServer ,
13+ } from './inject'
1114import type { TMatchVariable } from './parser'
12- import type { IBundle , Options } from './types'
13-
14- import type { OutputOptions } from 'rollup'
15+ import type { Options } from './types'
1516
1617const unplugin = createUnplugin < Options > (
1718 ( options : Options = { } ) : any => {
@@ -22,13 +23,12 @@ const unplugin = createUnplugin<Options>(
2223 )
2324 // 预处理 css 文件
2425 const CSSFileModuleMap = preProcessCSS ( userOptions )
25- let vbindVariableList = new Map < string , TMatchVariable > ( )
26+ const vbindVariableList = new Map < string , TMatchVariable > ( )
2627 let isScriptSetup = false
2728 return [
2829 {
2930 name : NAME ,
3031 enforce : 'pre' ,
31-
3232 transformInclude ( id : string ) {
3333 return filter ( id )
3434 } ,
@@ -38,13 +38,15 @@ const unplugin = createUnplugin<Options>(
3838 if ( id . endsWith ( '.vue' ) ) {
3939 const { descriptor } = parse ( code )
4040 isScriptSetup = ! ! descriptor . scriptSetup
41- const vbindVariableListByPath = getVBindVariableListByPath ( descriptor , id , CSSFileModuleMap )
41+ const {
42+ vbindVariableListByPath,
43+ injectCSSContent,
44+ } = getVBindVariableListByPath ( descriptor , id , CSSFileModuleMap , ! ! userOptions . dev )
4245 const variableName = getVariable ( descriptor )
4346 vbindVariableList . set ( id , matchVariable ( vbindVariableListByPath , variableName ) )
44- if ( ! userOptions . dev ) {
45- // 1.获取当前组件下 importer 的 文件内容
46- // 2. 注入到 sfc 中,(替换 v-bind-m -> v-bind)
47- }
47+
48+ if ( ! userOptions . dev )
49+ code = injectCssOnBuild ( code , injectCSSContent , descriptor )
4850 }
4951 return code
5052 } catch ( err : unknown ) {
@@ -61,7 +63,7 @@ const unplugin = createUnplugin<Options>(
6163 // transform in dev
6264 if ( userOptions . dev ) {
6365 if ( id . endsWith ( '.vue' ) ) {
64- const injectRes = injectCSSVars ( code , vbindVariableList . get ( id ) , isScriptSetup , userOptions . dev )
66+ const injectRes = injectCSSVars ( code , vbindVariableList . get ( id ) , isScriptSetup )
6567 code = injectRes . code
6668 injectRes . vbindVariableList && vbindVariableList . set ( id , injectRes . vbindVariableList )
6769 }
0 commit comments