@@ -36,7 +36,7 @@ class HtmlWebpackPlugin {
36
36
}
37
37
38
38
apply ( compiler ) {
39
- // Wait for configuration preset plugions to apply all configure webpack defaults
39
+ // Wait for configuration preset plugins to apply all configure webpack defaults
40
40
compiler . hooks . initialize . tap ( 'HtmlWebpackPlugin' , ( ) => {
41
41
const userOptions = this . userOptions ;
42
42
@@ -74,7 +74,7 @@ class HtmlWebpackPlugin {
74
74
assert ( options . inject === true || options . inject === false || options . inject === 'head' || options . inject === 'body' , 'inject needs to be set to true, false, "head" or "body' ) ;
75
75
76
76
// Default metaOptions if no template is provided
77
- if ( ! userOptions . template && options . templateContent === false && options . meta ) {
77
+ if ( ! userOptions . template && ! isTemplateInDefaultLocation ( compiler . context ) && options . templateContent === false && options . meta ) {
78
78
const defaultMeta = {
79
79
// From https://developer.mozilla.org/en-US/docs/Mozilla/Mobile/Viewport_meta_tag
80
80
viewport : 'width=device-width, initial-scale=1'
@@ -152,6 +152,11 @@ class HtmlWebpackPlugin {
152
152
}
153
153
}
154
154
155
+ function isTemplateInDefaultLocation ( context ) {
156
+ const template = path . resolve ( context , 'src/index.ejs' ) ;
157
+ return fs . existsSync ( template ) ;
158
+ }
159
+
155
160
/**
156
161
* connect the html-webpack-plugin to the webpack compiler lifecycle hooks
157
162
*
@@ -1018,8 +1023,9 @@ function hookIntoCompiler (compiler, options, plugin) {
1018
1023
*/
1019
1024
function getFullTemplatePath ( template , context ) {
1020
1025
if ( template === 'auto' ) {
1021
- template = path . resolve ( context , 'src/index.ejs' ) ;
1022
- if ( ! fs . existsSync ( template ) ) {
1026
+ if ( isTemplateInDefaultLocation ( context ) ) {
1027
+ template = path . resolve ( context , 'src/index.ejs' ) ;
1028
+ } else {
1023
1029
template = path . join ( __dirname , 'default_index.ejs' ) ;
1024
1030
}
1025
1031
}
0 commit comments