@@ -40,8 +40,12 @@ class UmdMainTemplatePlugin {
4040 }
4141
4242 apply ( compilation ) {
43- const mainTemplate = compilation . mainTemplate ;
44- compilation . templatesPlugin ( "render-with-entry" , ( source , chunk , hash ) => {
43+ const {
44+ mainTemplate,
45+ chunkTemplate
46+ } = compilation ;
47+
48+ const onRenderWithEntry = ( source , chunk , hash ) => {
4549 let externals = chunk . getModules ( ) . filter ( m => m . external && ( m . externalType === "umd" || m . externalType === "umd2" ) ) ;
4650 const optionalExternals = [ ] ;
4751 let requiredExternals = [ ] ;
@@ -172,14 +176,20 @@ class UmdMainTemplatePlugin {
172176 " }\n"
173177 ) +
174178 "})(typeof self !== 'undefined' ? self : this, function(" + externalsArguments ( externals ) + ") {\nreturn " , "webpack/universalModuleDefinition" ) , source , ";\n})" ) ;
175- } ) ;
176- mainTemplate . plugin ( "global-hash-paths" , ( paths ) => {
179+ } ;
180+
181+ for ( const template of [ mainTemplate , chunkTemplate ] ) {
182+ template . hooks . renderWithEntry . tap ( "UmdMainTemplatePlugin" , onRenderWithEntry ) ;
183+ }
184+
185+ mainTemplate . hooks . globalHashPaths . tap ( "UmdMainTemplatePlugin" , ( paths ) => {
177186 if ( this . names . root ) paths = paths . concat ( this . names . root ) ;
178187 if ( this . names . amd ) paths = paths . concat ( this . names . amd ) ;
179188 if ( this . names . commonjs ) paths = paths . concat ( this . names . commonjs ) ;
180189 return paths ;
181190 } ) ;
182- mainTemplate . plugin ( "hash" , ( hash ) => {
191+
192+ mainTemplate . hooks . hash . tap ( "UmdMainTemplatePlugin" , ( hash ) => {
183193 hash . update ( "umd" ) ;
184194 hash . update ( `${ this . names . root } ` ) ;
185195 hash . update ( `${ this . names . amd } ` ) ;
0 commit comments