@@ -27,6 +27,8 @@ const getHtmlWebpackPluginHooks = require('./lib/hooks.js').getHtmlWebpackPlugin
27
27
const fsStatAsync = promisify ( fs . stat ) ;
28
28
const fsReadFileAsync = promisify ( fs . readFile ) ;
29
29
30
+ const webpackMajorVersion = Number ( require ( 'webpack/package.json' ) . version . split ( '.' ) [ 0 ] ) ;
31
+
30
32
class HtmlWebpackPlugin {
31
33
/**
32
34
* @param {HtmlWebpackOptions } [options]
@@ -149,12 +151,16 @@ class HtmlWebpackPlugin {
149
151
compilation . errors . push ( prettyError ( templateResult . error , compiler . context ) . toString ( ) ) ;
150
152
}
151
153
152
- const childCompilationOutputName = compilation . mainTemplate . getAssetPath ( this . options . filename , 'compiledEntry' in templateResult ? {
154
+ const compiledEntries = 'compiledEntry' in templateResult ? {
153
155
hash : templateResult . compiledEntry . hash ,
154
156
chunk : templateResult . compiledEntry . entry
155
157
} : {
156
158
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 ) ;
158
164
159
165
// If the child compilation was not executed during a previous main compile run
160
166
// it is a cached result
@@ -529,7 +535,10 @@ class HtmlWebpackPlugin {
529
535
* if a path publicPath is set in the current webpack config use it otherwise
530
536
* fallback to a relative path
531
537
*/
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
+
533
542
const isPublicPathDefined = webpackPublicPath . trim ( ) !== '' ;
534
543
let publicPath = isPublicPathDefined
535
544
// If a hard coded public path exists use it
0 commit comments