@@ -221,22 +221,6 @@ export class ModuleMinifierPlugin implements webpack.Plugin {
221221 }
222222 }
223223
224- /**
225- * Callback to invoke for a chunk during render to replace the modules with CHUNK_MODULES_TOKEN
226- */
227- function dehydrateAsset ( modules : Source , chunk : webpack . compilation . Chunk ) : Source {
228- for ( const mod of chunk . modulesIterable ) {
229- if ( mod . id === null || ! submittedModules . has ( mod . id ) ) {
230- console . error (
231- `Chunk ${ chunk . id } failed to render module ${ mod . id } for ${ ( mod as IExtendedModule ) . resource } `
232- ) ;
233- }
234- }
235-
236- // Discard the rendered modules
237- return new RawSource ( CHUNK_MODULES_TOKEN ) ;
238- }
239-
240224 const { minifier } = this ;
241225
242226 const cleanupMinifier : ( ( ) => Promise < void > ) | undefined = minifier . ref ?.( ) ;
@@ -467,7 +451,7 @@ export class ModuleMinifierPlugin implements webpack.Plugin {
467451 }
468452 ) ;
469453 } else {
470- // Skip minification for all other assets , though the modules still are
454+ // This isn't a JS asset. Don't try to minify the asset wrapper , though if it contains modules, those might still get replaced with minified versions.
471455 minifiedAssets . set ( assetName , {
472456 // Still need to restore ids
473457 source : postProcessCode ( new ReplaceSource ( asset ) , assetName ) ,
@@ -509,9 +493,32 @@ export class ModuleMinifierPlugin implements webpack.Plugin {
509493 }
510494 ) ;
511495
512- for ( const template of [ compilation . chunkTemplate , compilation . mainTemplate ] ) {
513- ( template as unknown as IExtendedChunkTemplate ) . hooks . modules . tap ( TAP_AFTER , dehydrateAsset ) ;
514- }
496+ // This function is written twice because the parameter order is not the same between the two hooks
497+ ( compilation . chunkTemplate as unknown as IExtendedChunkTemplate ) . hooks . modules . tap (
498+ TAP_AFTER ,
499+ ( source : Source , chunk : webpack . compilation . Chunk , moduleTemplate : unknown ) => {
500+ if ( moduleTemplate !== compilation . moduleTemplates . javascript ) {
501+ // This is not a JavaScript asset
502+ return source ;
503+ }
504+
505+ // Discard the rendered modules
506+ return new RawSource ( CHUNK_MODULES_TOKEN ) ;
507+ }
508+ ) ;
509+
510+ ( compilation . mainTemplate as unknown as IExtendedChunkTemplate ) . hooks . modules . tap (
511+ TAP_AFTER ,
512+ ( source : Source , chunk : webpack . compilation . Chunk , hash : unknown , moduleTemplate : unknown ) => {
513+ if ( moduleTemplate !== compilation . moduleTemplates . javascript ) {
514+ // This is not a JavaScript asset
515+ return source ;
516+ }
517+
518+ // Discard the rendered modules
519+ return new RawSource ( CHUNK_MODULES_TOKEN ) ;
520+ }
521+ ) ;
515522 }
516523 ) ;
517524 }
0 commit comments