@@ -171,8 +171,38 @@ class CssMinimizerPlugin {
171171 : Math . min ( Number ( parallel ) || 0 , cpus . length - 1 ) ;
172172 }
173173
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+ }
176206
177207 let input ;
178208 let inputSourceMap ;
@@ -190,7 +220,7 @@ class CssMinimizerPlugin {
190220 inputSourceMap = map ;
191221
192222 compilation . warnings . push (
193- new Error ( `${ file } contains invalid source map` )
223+ new Error ( `${ name } contains invalid source map` )
194224 ) ;
195225 }
196226 }
@@ -222,7 +252,7 @@ class CssMinimizerPlugin {
222252 compilation . errors . push (
223253 CssMinimizerPlugin . buildError (
224254 error ,
225- file ,
255+ name ,
226256 sourceMap ,
227257 new RequestShortener ( compiler . context )
228258 )
@@ -236,7 +266,7 @@ class CssMinimizerPlugin {
236266 if ( map ) {
237267 outputSource = new SourceMapSource (
238268 code ,
239- file ,
269+ name ,
240270 map ,
241271 input ,
242272 inputSourceMap ,
@@ -246,16 +276,17 @@ class CssMinimizerPlugin {
246276 outputSource = new RawSource ( code ) ;
247277 }
248278
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+ } ) ;
252283
253284 // Handling warnings
254285 if ( warnings && warnings . length > 0 ) {
255286 warnings . forEach ( ( warning ) => {
256287 const builtWarning = CssMinimizerPlugin . buildWarning (
257288 warning ,
258- file ,
289+ name ,
259290 sourceMap ,
260291 new RequestShortener ( compiler . context ) ,
261292 this . options . warningsFilter
@@ -269,7 +300,7 @@ class CssMinimizerPlugin {
269300 } ;
270301
271302 const task = {
272- file ,
303+ name ,
273304 input,
274305 inputSourceMap,
275306 map : this . options . sourceMap ,
@@ -299,11 +330,11 @@ class CssMinimizerPlugin {
299330 'css-minimizer-webpack-plugin' : require ( '../package.json' ) . version ,
300331 'css-minimizer-webpack-plugin-options' : this . options ,
301332 nodeVersion : process . version ,
302- filename : file ,
333+ filename : name ,
303334 contentHash : digest . substr ( 0 , hashDigestLength ) ,
304335 } ;
305336
306- task . cacheKeys = this . options . cacheKeys ( defaultCacheKeys , file ) ;
337+ task . cacheKeys = this . options . cacheKeys ( defaultCacheKeys , name ) ;
307338 }
308339 } else {
309340 // For webpack@5 cache
0 commit comments