@@ -171,8 +171,38 @@ class CssMinimizerPlugin {
171
171
: Math . min ( Number ( parallel ) || 0 , cpus . length - 1 ) ;
172
172
}
173
173
174
- * taskGenerator ( compiler , compilation , file ) {
175
- const assetSource = compilation . assets [ file ] ;
174
+ // eslint-disable-next-line consistent-return
175
+ static getAsset ( compilation , name ) {
176
+ // New API
177
+ if ( compilation . getAsset ) {
178
+ return compilation . getAsset ( name ) ;
179
+ }
180
+
181
+ if ( compilation . assets [ name ] ) {
182
+ return { name, source : compilation . assets [ name ] , info : { } } ;
183
+ }
184
+ }
185
+
186
+ static updateAsset ( compilation , name , newSource , assetInfo ) {
187
+ // New API
188
+ if ( compilation . updateAsset ) {
189
+ compilation . updateAsset ( name , newSource , assetInfo ) ;
190
+ }
191
+
192
+ // eslint-disable-next-line no-param-reassign
193
+ compilation . assets [ name ] = newSource ;
194
+ }
195
+
196
+ * taskGenerator ( compiler , compilation , name ) {
197
+ const { info, source : assetSource } = CssMinimizerPlugin . getAsset (
198
+ compilation ,
199
+ name
200
+ ) ;
201
+
202
+ // Skip double minimize assets from child compilation
203
+ if ( info . minimized ) {
204
+ yield false ;
205
+ }
176
206
177
207
let input ;
178
208
let inputSourceMap ;
@@ -190,7 +220,7 @@ class CssMinimizerPlugin {
190
220
inputSourceMap = map ;
191
221
192
222
compilation . warnings . push (
193
- new Error ( `${ file } contains invalid source map` )
223
+ new Error ( `${ name } contains invalid source map` )
194
224
) ;
195
225
}
196
226
}
@@ -222,7 +252,7 @@ class CssMinimizerPlugin {
222
252
compilation . errors . push (
223
253
CssMinimizerPlugin . buildError (
224
254
error ,
225
- file ,
255
+ name ,
226
256
sourceMap ,
227
257
new RequestShortener ( compiler . context )
228
258
)
@@ -236,7 +266,7 @@ class CssMinimizerPlugin {
236
266
if ( map ) {
237
267
outputSource = new SourceMapSource (
238
268
code ,
239
- file ,
269
+ name ,
240
270
map ,
241
271
input ,
242
272
inputSourceMap ,
@@ -246,16 +276,17 @@ class CssMinimizerPlugin {
246
276
outputSource = new RawSource ( code ) ;
247
277
}
248
278
249
- // Updating assets
250
- // eslint-disable-next-line no-param-reassign
251
- compilation . assets [ file ] = outputSource ;
279
+ CssMinimizerPlugin . updateAsset ( compilation , name , outputSource , {
280
+ ...info ,
281
+ minimized : true ,
282
+ } ) ;
252
283
253
284
// Handling warnings
254
285
if ( warnings && warnings . length > 0 ) {
255
286
warnings . forEach ( ( warning ) => {
256
287
const builtWarning = CssMinimizerPlugin . buildWarning (
257
288
warning ,
258
- file ,
289
+ name ,
259
290
sourceMap ,
260
291
new RequestShortener ( compiler . context ) ,
261
292
this . options . warningsFilter
@@ -269,7 +300,7 @@ class CssMinimizerPlugin {
269
300
} ;
270
301
271
302
const task = {
272
- file ,
303
+ name ,
273
304
input,
274
305
inputSourceMap,
275
306
map : this . options . sourceMap ,
@@ -299,11 +330,11 @@ class CssMinimizerPlugin {
299
330
'css-minimizer-webpack-plugin' : require ( '../package.json' ) . version ,
300
331
'css-minimizer-webpack-plugin-options' : this . options ,
301
332
nodeVersion : process . version ,
302
- filename : file ,
333
+ filename : name ,
303
334
contentHash : digest . substr ( 0 , hashDigestLength ) ,
304
335
} ;
305
336
306
- task . cacheKeys = this . options . cacheKeys ( defaultCacheKeys , file ) ;
337
+ task . cacheKeys = this . options . cacheKeys ( defaultCacheKeys , name ) ;
307
338
}
308
339
} else {
309
340
// For webpack@5 cache
0 commit comments