@@ -112,43 +112,47 @@ export class BundleWriter {
112
112
}
113
113
114
114
let index = 1 ;
115
- const writeBundle = ( bundle : Bundle ) => {
116
- return bundle . context . output . writeCurrent ( bundle . generatedCode ) . then ( output => {
117
- let entryString ;
118
- if ( bundle . quantumBit && bundle . quantumBit . entry ) {
119
- entryString = bundle . quantumBit . entry . getFuseBoxFullPath ( ) ;
120
- }
121
- bundleManifest [ bundle . name ] = {
122
- fileName : output . filename ,
123
- hash : output . hash ,
124
- type : "js" ,
125
- entry : entryString ,
126
- absPath : output . path ,
127
- webIndexed : ! bundle . quantumBit ,
128
- relativePath : output . relativePath ,
129
- } ;
130
- // if this bundle belongs to splitting
131
- // we need to remember the generated file name and store
132
- // and then pass to the API
133
- if ( bundle . quantumBit ) {
134
- const splitOpts : any = [ output . relativePath , bundle . quantumBit . entry . getID ( ) ] ;
135
- splitFileOptions . i [ bundle . quantumBit . name ] = splitOpts ;
136
- if ( bundle . quantumBit . cssCollection ) {
137
- let cssName = bundle . quantumBit . name ;
138
- if ( ! / \. c s s $ / . test ( cssName ) ) {
139
- cssName = ` ${ cssName } .css` ;
140
- }
141
- const splitConfig = this . core . context . quantumSplitConfig ;
142
- if ( bundle . quantumBit && splitConfig && splitConfig . resolveOptions ) {
143
- const dest = splitConfig . getDest ( ) ;
144
- cssName = joinFuseBoxPath ( dest , cssName ) ;
145
- }
146
- splitOpts . push ( { css : true , name : cssName } ) ;
115
+ const writeBundle = async ( bundle : Bundle ) => {
116
+ const output = await bundle . context . output . writeCurrent ( bundle . generatedCode ) ;
117
+ let entryString ;
118
+ if ( bundle . quantumBit && bundle . quantumBit . entry ) {
119
+ entryString = bundle . quantumBit . entry . getFuseBoxFullPath ( ) ;
120
+ }
121
+ bundleManifest [ bundle . name ] = {
122
+ fileName : output . filename ,
123
+ hash : output . hash ,
124
+ type : "js" ,
125
+ entry : entryString ,
126
+ absPath : output . path ,
127
+ webIndexed : ! bundle . quantumBit ,
128
+ relativePath : output . relativePath ,
129
+ } ;
130
+ // if this bundle belongs to splitting
131
+ // we need to remember the generated file name and store
132
+ // and then pass to the API
133
+ if ( bundle . quantumBit ) {
134
+ const splitOpts : any = [ output . relativePath , bundle . quantumBit . entry . getID ( ) ] ;
135
+ splitFileOptions . i [ bundle . quantumBit . name ] = splitOpts ;
136
+ const cssCollection = bundle . quantumBit . cssCollection ;
137
+ if ( cssCollection ) {
138
+ let cssName = bundle . quantumBit . name ;
139
+ if ( ! / \ .c s s $ / . test ( cssName ) ) {
140
+ cssName = ` ${ cssName } .css` ;
141
+ }
142
+ const splitConfig = this . core . context . quantumSplitConfig ;
143
+ const output = await writeCSS ( cssCollection , cssName ) ;
144
+ if ( bundle . quantumBit && splitConfig && splitConfig . resolveOptions ) {
145
+ const dest = splitConfig . getDest ( ) ;
146
+ cssName = joinFuseBoxPath ( dest , output . filename ) ;
147
147
}
148
+ splitOpts . push ( { css : true , name : cssName } ) ;
148
149
}
149
- } ) ;
150
+ }
150
151
} ;
151
152
const writeCSS = async ( cssCollection : CSSCollection , key : string ) => {
153
+ if ( cssCollection . written ) {
154
+ return ;
155
+ }
152
156
const cssData = cssCollection . collection ;
153
157
154
158
if ( cssData . size > 0 ) {
@@ -194,13 +198,11 @@ export class BundleWriter {
194
19
1E0A
8
if ( useSourceMaps ) {
195
199
output . writeToOutputFolder ( cssCollection . sourceMapsPath , cssCollection . sourceMap ) ;
196
200
}
201
+ cssCollection . written = true ;
202
+ return cssResultData ;
197
203
}
198
204
} ;
199
205
200
- if ( this . core . opts . shouldGenerateCSS ( ) ) {
201
- this . core . cssCollection . forEach ( writeCSS ) ;
202
- }
203
-
204
206
return each ( producer . bundles , ( bundle : Bundle ) => {
205
207
if ( bundle . name === "api.js" ) {
206
208
// has to be the highest priority
@@ -245,12 +247,19 @@ export class BundleWriter {
245
247
if ( this . core . opts . shouldUglify ( ) ) {
246
248
this . uglifyBundle ( bundle ) ;
247
249
}
248
-
249
250
await writeBundle ( bundle ) ;
250
251
}
251
252
}
252
253
}
253
254
} )
255
+ . then ( async ( ) => {
256
+ if ( this . core . opts . shouldGenerateCSS ( ) ) {
257
+ for ( const item of this . core . cssCollection ) {
258
+ const cssCollection = item [ 1 ] ;
259
+ await writeCSS ( cssCollection , item [ 0 ] ) ;
260
+ }
261
+ }
262
+ } )
254
263
. then ( ( ) => {
255
264
const manifestPath = this . core . opts . getManifestFilePath ( ) ;
256
265
if ( manifestPath ) {
0 commit comments