@@ -121,23 +121,46 @@ class Project {
121
121
}
122
122
fixCss ( ) {
123
123
let config = this . config . getConfig ( ) ,
124
- entry = config . entry ,
124
+ entries = config . entry ,
125
125
cssExtNames = config . entryExtNames . css ,
126
126
fps = [ ] ;
127
127
128
128
const contextPathRelativeToCwd = sysPath . relative ( config . context , this . cwd ) || '.'
129
129
130
- for ( let key in entry ) {
131
- let extName = sysPath . extname ( entry [ key ] ) ;
130
+ for ( let key in entries ) {
131
+ const entryItem = entries [ key ] ,
132
+ entry = Array . isArray ( entryItem ) ? entryItem [ entryItem . length - 1 ] : entryItem ,
133
+ extName = sysPath . extname ( entry ) ;
134
+
132
135
if ( cssExtNames . indexOf ( extName ) > - 1 ) {
133
- let name = sysPath . basename ( entry [ key ] , extName ) ,
134
- ofp = sysPath . join ( config . context , entry [ key ] ) ,
135
- np = entry [ key ] = './' + sysPath . join ( contextPathRelativeToCwd , '/.cache' , entry [ key ] + '.js' ) ,
136
- fp = sysPath . join ( config . context , np ) ;
137
-
138
- mkdirp . sync ( sysPath . dirname ( fp ) ) ;
139
- fs . writeFileSync ( fp , 'require("' + sysPath . relative ( sysPath . dirname ( fp ) , ofp ) + '");' , 'utf-8' ) ;
140
- fps . push ( fp ) ;
136
+ let requireFilePath = entries [ key ] = './' + sysPath . join ( contextPathRelativeToCwd , '/.cache' , entry + '.js' ) ,
137
+ cacheFilePath = sysPath . join ( config . context , requireFilePath ) ;
138
+
139
+ mkdirp . sync ( sysPath . dirname ( cacheFilePath ) ) ;
140
+
141
+ // 将原有entry的css路径写到js中
142
+ if ( Array . isArray ( entryItem ) ) {
143
+ // clear
144
+ fs . writeFileSync ( cacheFilePath , '' , 'utf-8' ) ;
145
+
146
+ entryItem . forEach ( ( cssPath , i ) => {
147
+ const originCssPath = sysPath . join ( config . context , cssPath )
148
+ fs . appendFileSync (
149
+ cacheFilePath ,
150
+ 'require("' + sysPath . relative ( sysPath . dirname ( cacheFilePath ) , originCssPath ) + '");' ,
151
+ 'utf-8'
152
+ ) ;
153
+ } )
154
+ } else {
155
+ const originCssPath = sysPath . join ( config . context , entry )
156
+ fs . writeFileSync (
157
+ cacheFilePath ,
158
+ 'require("' + sysPath . relative ( sysPath . dirname ( cacheFilePath ) , originCssPath ) + '");' ,
159
+ 'utf-8'
160
+ ) ;
161
+ }
162
+
163
+ fps . push ( cacheFilePath ) ;
141
164
}
142
165
}
143
166
config . plugins . push ( new ExtractTextPlugin ( config . output . filename . replace ( '[ext]' , '.css' ) ) ) ;
0 commit comments