@@ -27,6 +27,8 @@ const getHtmlWebpackPluginHooks = require('./lib/hooks.js').getHtmlWebpackPlugin
2727const fsStatAsync = promisify ( fs . stat ) ;
2828const fsReadFileAsync = promisify ( fs . readFile ) ;
2929
30+ const webpackMajorVersion = Number ( require ( 'webpack/package.json' ) . version . split ( '.' ) [ 0 ] ) ;
31+
3032class HtmlWebpackPlugin {
3133 /**
3234 * @param {HtmlWebpackOptions } [options]
@@ -149,12 +151,16 @@ class HtmlWebpackPlugin {
149151 compilation . errors . push ( prettyError ( templateResult . error , compiler . context ) . toString ( ) ) ;
150152 }
151153
152- const childCompilationOutputName = compilation . mainTemplate . getAssetPath ( this . options . filename , 'compiledEntry' in templateResult ? {
154+ const compiledEntries = 'compiledEntry' in templateResult ? {
153155 hash : templateResult . compiledEntry . hash ,
154156 chunk : templateResult . compiledEntry . entry
155157 } : {
156158 hash : templateResult . mainCompilationHash
157- } ) ;
159+ } ;
160+
161+ const childCompilationOutputName = webpackMajorVersion === 4
162+ ? compilation . mainTemplate . getAssetPath ( this . options . filename , compiledEntries )
163+ : compilation . getAssetPath ( this . options . filename , compiledEntries ) ;
158164
159165 // If the child compilation was not executed during a previous main compile run
160166 // it is a cached result
@@ -529,7 +535,10 @@ class HtmlWebpackPlugin {
529535 * if a path publicPath is set in the current webpack config use it otherwise
530536 * fallback to a relative path
531537 */
532- const webpackPublicPath = compilation . mainTemplate . getPublicPath ( { hash : compilationHash } ) ;
538+ const webpackPublicPath = webpackMajorVersion === 4
539+ ? compilation . mainTemplate . getPublicPath ( { hash : compilationHash } )
540+ : compilation . getAssetPath ( compilation . outputOptions . publicPath , { hash : compilationHash } ) ;
541+
533542 const isPublicPathDefined = webpackPublicPath . trim ( ) !== '' ;
534543 let publicPath = isPublicPathDefined
535544 // If a hard coded public path exists use it
0 commit comments