@@ -30,6 +30,9 @@ class HtmlWebpackPlugin {
30
30
* @param {Partial<HtmlWebpackPluginOptions> } [options]
31
31
*/
32
32
constructor ( options ) {
33
+ /** @type {Partial<HtmlWebpackPluginOptions> } */
34
+ const userOptions = options || { } ;
35
+
33
36
// Default options
34
37
/** @type {HtmlWebpackPluginOptions } */
35
38
const defaultOptions = {
@@ -51,8 +54,19 @@ class HtmlWebpackPlugin {
51
54
title : 'Webpack App' ,
52
55
xhtml : false
53
56
} ;
57
+
54
58
/** @type {HtmlWebpackPluginOptions } */
55
- this . options = Object . assign ( defaultOptions , options ) ;
59
+ this . options = Object . assign ( defaultOptions , userOptions ) ;
60
+
61
+ // Default metaOptions if no template is provided
62
+ if ( ! userOptions . template && this . options . templateContent === false && this . options . meta ) {
63
+ const defaultMeta = {
64
+ // From https://developer.mozilla.org/en-US/docs/Mozilla/Mobile/Viewport_meta_tag
65
+ viewport : 'width=device-width, initial-scale=1'
66
+ } ;
67
+ this . options . meta = Object . assign ( { } , this . options . meta , defaultMeta , userOptions . meta ) ;
68
+ }
69
+
56
70
// Instance variables to keep caching information
57
71
// for multiple builds
58
72
this . childCompilerHash = undefined ;
@@ -502,16 +516,21 @@ class HtmlWebpackPlugin {
502
516
// Make tags self-closing in case of xhtml
503
517
// Turn { "viewport" : "width=500, initial-scale=1" } into
504
518
// [{ name:"viewport" content:"width=500, initial-scale=1" }]
505
- const metaTagAttributeObjects = Object . keys ( metaOptions ) . map ( ( metaName ) => {
519
+ const metaTagAttributeObjects = Object . keys ( metaOptions )
520
+ . map ( ( metaName ) => {
506
521
const metaTagContent = metaOptions [ metaName ] ;
507
522
return ( typeof metaTagContent === 'string' ) ? {
508
523
name : metaName ,
509
524
content : metaTagContent
510
525
} : metaTagContent ;
511
- } ) ;
526
+ } )
527
+ . filter ( ( attribute ) => attribute !== false ) ;
512
528
// Turn [{ name:"viewport" content:"width=500, initial-scale=1" }] into
513
529
// the html-webpack-plugin tag structure
514
530
return metaTagAttributeObjects . map ( ( metaTagAttributes ) => {
531
+ if ( metaTagAttributes === false ) {
532
+ throw new Error ( 'Invalid meta tag' ) ;
533
+ }
515
534
return {
516
535
tagName : 'meta' ,
517
536
voidTag : true ,
0 commit comments