@@ -786,16 +786,25 @@ class HtmlWebpackPlugin {
786786 * @returns {Array<HtmlTagObject> }
787787 */
788788 generatedScriptTags ( jsAssets ) {
789- return jsAssets . map ( scriptAsset => ( {
790- tagName : 'script' ,
791- voidTag : false ,
792- meta : { plugin : 'html-webpack-plugin' } ,
793- attributes : {
794- defer : this . options . scriptLoading === 'defer' ,
795- type : this . options . scriptLoading === 'module' ? 'module' : undefined ,
796- src : scriptAsset
789+ // @ts -ignore
790+ return jsAssets . map ( src => {
791+ const attributes = { } ;
792+
793+ if ( this . options . scriptLoading === 'defer' ) {
794+ attributes . defer = true ;
795+ } else if ( this . options . scriptLoading === 'module' ) {
796+ attributes . type = 'module' ;
797797 }
798- } ) ) ;
798+
799+ attributes . src = src ;
800+
801+ return {
802+ tagName : 'script' ,
803+ voidTag : false ,
804+ meta : { plugin : 'html-webpack-plugin' } ,
805+ attributes
806+ } ;
807+ } ) ;
799808 }
800809
801810 /**
@@ -820,23 +829,19 @@ class HtmlWebpackPlugin {
820829 /**
821830 * Generate an optional base tag
822831 *
823- * @param {false | string | {[attributeName: string]: string} } baseOption
832+ * @param {string | {[attributeName: string]: string} } base
824833 * @returns {Array<HtmlTagObject> }
825834 */
826- generateBaseTag ( baseOption ) {
827- if ( baseOption === false ) {
828- return [ ] ;
829- } else {
830- return [ {
831- tagName : 'base' ,
832- voidTag : true ,
833- meta : { plugin : 'html-webpack-plugin' } ,
834- // attributes e.g. { href:"http://example.com/page.html" target:"_blank" }
835- attributes : ( typeof baseOption === 'string' ) ? {
836- href : baseOption
837- } : baseOption
838- } ] ;
839- }
835+ generateBaseTag ( base ) {
836+ return [ {
837+ tagName : 'base' ,
838+ voidTag : true ,
839+ meta : { plugin : 'html-webpack-plugin' } ,
840+ // attributes e.g. { href:"http://example.com/page.html" target:"_blank" }
841+ attributes : typeof base === 'string' ? {
842+ href : base
843+ } : base
844+ } ] ;
840845 }
841846
842847 /**
@@ -883,21 +888,17 @@ class HtmlWebpackPlugin {
883888 * Generate a favicon tag for the given file path
884889 *
885890 * @private
886- * @param {string| undefined } faviconPath
891+ * @param {string } favicon
887892 * @returns {Array<HtmlTagObject> }
888893 */
889- generateFaviconTag ( faviconPath ) {
890- if ( ! faviconPath ) {
891- return [ ] ;
892- }
893-
894+ generateFaviconTag ( favicon ) {
894895 return [ {
895896 tagName : 'link' ,
896897 voidTag : true ,
897898 meta : { plugin : 'html-webpack-plugin' } ,
898899 attributes : {
899900 rel : 'icon' ,
900- href : faviconPath
901+ href : favicon
901902 }
902903 } ] ;
903904 }
@@ -1052,9 +1053,9 @@ class HtmlWebpackPlugin {
10521053 scripts : this . generatedScriptTags ( assets . js ) ,
10531054 styles : this . generateStyleTags ( assets . css ) ,
10541055 meta : [
1055- ...this . generateBaseTag ( this . options . base ) ,
1056+ ...( this . options . base !== false ? this . generateBaseTag ( this . options . base ) : [ ] ) ,
10561057 ...this . generatedMetaTags ( this . options . meta ) ,
1057- ...this . generateFaviconTag ( assets . favicon )
1058+ ...( assets . favicon ? this . generateFaviconTag ( assets . favicon ) : [ ] )
10581059 ]
10591060 } ,
10601061 outputName,
0 commit comments