@@ -252,8 +252,11 @@ function hookIntoCompiler (compiler, options, plugin) {
252
252
// it is a cached result
253
253
const isCompilationCached = templateResult . mainCompilationHash !== compilation . hash ;
254
254
255
- // Turn the entry point names into file paths
256
- const assets = htmlWebpackPluginAssets ( compilation , childCompilationOutputName , sortedEntryNames , options . publicPath ) ;
255
+ /** The public path used inside the html file */
256
+ const htmlPublicPath = getPublicPath ( compilation , childCompilationOutputName , options . publicPath ) ;
257
+
258
+ /** Generated file paths from the entry point names */
259
+ const assets = htmlWebpackPluginAssets ( compilation , sortedEntryNames , htmlPublicPath ) ;
257
260
258
261
// If the template and the assets did not change we don't have to emit the html
259
262
const newAssetJson = JSON . stringify ( getAssetFiles ( assets ) ) ;
@@ -327,7 +330,6 @@ function hookIntoCompiler (compiler, options, plugin) {
327
330
? plugin . evaluateCompilationResult ( templateResult . compiledEntry . content , options . template )
328
331
: Promise . reject ( new Error ( 'Child compilation contained no compiledEntry' ) ) ;
329
332
} ) ;
330
-
331
333
const templateExectutionPromise = Promise . all ( [ assetsPromise , assetTagGroupsPromise , templateEvaluationPromise ] )
332
334
// Execute the template
333
335
. then ( ( [ assetsHookResult , assetTags , compilationResult ] ) => typeof compilationResult !== 'function'
@@ -545,20 +547,15 @@ function hookIntoCompiler (compiler, options, plugin) {
545
547
}
546
548
547
549
/**
548
- * The htmlWebpackPluginAssets extracts the asset information of a webpack compilation
549
- * for all given entry names
550
+ * Generate the relative or absolute base url to reference images, css, and javascript files
551
+ * from within the html file - the publicPath
552
+ *
550
553
* @param {WebpackCompilation } compilation
551
- * @param {string[] } entryNames
554
+ * @param {string } childCompilationOutputName
552
555
* @param {string | 'auto' } customPublicPath
553
- * @returns {{
554
- publicPath: string,
555
- js: Array<string>,
556
- css: Array<string>,
557
- manifest?: string,
558
- favicon?: string
559
- }}
556
+ * @returns {string }
560
557
*/
561
- function htmlWebpackPluginAssets ( compilation , childCompilationOutputName , entryNames , customPublicPath ) {
558
+ function getPublicPath ( compilation , childCompilationOutputName , customPublicPath ) {
562
559
const compilationHash = compilation . hash ;
563
560
564
561
/**
@@ -587,6 +584,25 @@ function hookIntoCompiler (compiler, options, plugin) {
587
584
publicPath += '/' ;
588
585
}
589
586
587
+ return publicPath ;
588
+ }
589
+
590
+ /**
591
+ * The htmlWebpackPluginAssets extracts the asset information of a webpack compilation
592
+ * for all given entry names
593
+ * @param {WebpackCompilation } compilation
594
+ * @param {string[] } entryNames
595
+ * @param {string | 'auto' } publicPath
596
+ * @returns {{
597
+ publicPath: string,
598
+ js: Array<string>,
599
+ css: Array<string>,
600
+ manifest?: string,
601
+ favicon?: string
602
+ }}
603
+ */
604
+ function htmlWebpackPluginAssets ( compilation , entryNames , publicPath ) {
605
+ const compilationHash = compilation . hash ;
590
606
/**
591
607
* @type {{
592
608
publicPath: string,
@@ -598,7 +614,7 @@ function hookIntoCompiler (compiler, options, plugin) {
598
614
*/
599
615
const assets = {
600
616
// The public path
601
- publicPath : publicPath ,
617
+ publicPath,
602
618
// Will contain all js and mjs files
603
619
js : [ ] ,
604
620
// Will contain all css files
0 commit comments