@@ -786,16 +786,25 @@ class HtmlWebpackPlugin {
786
786
* @returns {Array<HtmlTagObject> }
787
787
*/
788
788
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' ;
797
797
}
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
+ } ) ;
799
808
}
800
809
801
810
/**
@@ -820,23 +829,19 @@ class HtmlWebpackPlugin {
820
829
/**
821
830
* Generate an optional base tag
822
831
*
823
- * @param {false | string | {[attributeName: string]: string} } baseOption
832
+ * @param {string | {[attributeName: string]: string} } base
824
833
* @returns {Array<HtmlTagObject> }
825
834
*/
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
+ } ] ;
840
845
}
841
846
842
847
/**
@@ -883,21 +888,17 @@ class HtmlWebpackPlugin {
883
888
* Generate a favicon tag for the given file path
884
889
*
885
890
* @private
886
- * @param {string| undefined } faviconPath
891
+ * @param {string } favicon
887
892
* @returns {Array<HtmlTagObject> }
888
893
*/
889
- generateFaviconTag ( faviconPath ) {
890
- if ( ! faviconPath ) {
891
- return [ ] ;
892
- }
893
-
894
+ generateFaviconTag ( favicon ) {
894
895
return [ {
895
896
tagName : 'link' ,
896
897
voidTag : true ,
897
898
meta : { plugin : 'html-webpack-plugin' } ,
898
899
attributes : {
899
900
rel : 'icon' ,
900
- href : faviconPath
901
+ href : favicon
901
902
}
902
903
} ] ;
903
904
}
@@ -1052,9 +1053,9 @@ class HtmlWebpackPlugin {
1052
1053
scripts : this . generatedScriptTags ( assets . js ) ,
1053
1054
styles : this . generateStyleTags ( assets . css ) ,
1054
1055
meta : [
1055
- ...this . generateBaseTag ( this . options . base ) ,
1056
+ ...( this . options . base !== false ? this . generateBaseTag ( this . options . base ) : [ ] ) ,
1056
1057
...this . generatedMetaTags ( this . options . meta ) ,
1057
- ...this . generateFaviconTag ( assets . favicon )
1058
+ ...( assets . favicon ? this . generateFaviconTag ( assets . favicon ) : [ ] )
1058
1059
]
1059
1060
} ,
1060
1061
outputName,
0 commit comments