@@ -36,7 +36,7 @@ class HtmlWebpackPlugin {
3636 }
3737
3838 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
4040 compiler . hooks . initialize . tap ( 'HtmlWebpackPlugin' , ( ) => {
4141 const userOptions = this . userOptions ;
4242
@@ -74,7 +74,7 @@ class HtmlWebpackPlugin {
7474 assert ( options . inject === true || options . inject === false || options . inject === 'head' || options . inject === 'body' , 'inject needs to be set to true, false, "head" or "body' ) ;
7575
7676 // 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 ) {
7878 const defaultMeta = {
7979 // From https://developer.mozilla.org/en-US/docs/Mozilla/Mobile/Viewport_meta_tag
8080 viewport : 'width=device-width, initial-scale=1'
@@ -152,6 +152,11 @@ class HtmlWebpackPlugin {
152152 }
153153}
154154
155+ function isTemplateInDefaultLocation ( context ) {
156+ const template = path . resolve ( context , 'src/index.ejs' ) ;
157+ return fs . existsSync ( template ) ;
158+ }
159+
155160/**
156161 * connect the html-webpack-plugin to the webpack compiler lifecycle hooks
157162 *
@@ -1018,8 +1023,9 @@ function hookIntoCompiler (compiler, options, plugin) {
10181023 */
10191024 function getFullTemplatePath ( template , context ) {
10201025 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 {
10231029 template = path . join ( __dirname , 'default_index.ejs' ) ;
10241030 }
10251031 }
0 commit comments