diff --git a/README.md b/README.md index d5877a03..2991b0d0 100644 --- a/README.md +++ b/README.md @@ -142,8 +142,8 @@ Allowed values are as follows |:--:|:--:|:-----:|:----------| |**`title`**|`{String}`|`Webpack App`|The title to use for the generated HTML document| |**`filename`**|`{String}`|`'index.html'`|The file to write the HTML to. Defaults to `index.html`. You can specify a subdirectory here too (eg: `assets/admin.html`)| -|**`template`**|`{String}`|``|`webpack` require path to the template. Please see the [docs](https://github.com/jantimon/html-webpack-plugin/blob/master/docs/template-option.md) for details| -|**[`templateParameters`](#)**|`{Boolean\|Object\|Function}`|``| Allows to overwrite the parameters used in the template | +|**`template`**|`{String}`|``|`webpack` relative or absolute path to the template. By default it will use `src/index.ejs` if it exists. Please see the [docs](https://github.com/jantimon/html-webpack-plugin/blob/master/docs/template-option.md) for details| +|**`templateParameters`**|`{Boolean\|Object\|Function}`|``| Allows to overwrite the parameters used in the template | |**`inject`**|`{Boolean\|String}`|`true`|`true \|\| 'head' \|\| 'body' \|\| false` Inject all assets into the given `template` or `templateContent`. When passing `true` or `'body'` all javascript resources will be placed at the bottom of the body element. `'head'` will place the scripts in the head element| |**`favicon`**|`{String}`|``|Adds the given favicon path to the output HTML| |**`meta`**|`{Object}`|`{}`|Allows to inject `meta`-tags. E.g. `meta: {viewport: 'width=device-width, initial-scale=1, shrink-to-fit=no'}`| diff --git a/index.js b/index.js index 4bf1cf25..ed3d11cd 100644 --- a/index.js +++ b/index.js @@ -38,7 +38,7 @@ class HtmlWebpackPlugin { // Default options /** @type {ProcessedHtmlWebpackOptions} */ const defaultOptions = { - template: path.join(__dirname, 'default_index.ejs'), + template: 'auto', templateContent: false, templateParameters: templateParametersGenerator, filename: 'index.html', @@ -908,6 +908,12 @@ class HtmlWebpackPlugin { * The webpack base resolution path for relative paths e.g. process.cwd() */ getFullTemplatePath (template, context) { + if (template === 'auto') { + template = path.resolve(context, 'src/index.ejs'); + if (!fs.existsSync(template)) { + template = path.join(__dirname, 'default_index.ejs'); + } + } // If the template doesn't use a loader use the lodash template loader if (template.indexOf('!') === -1) { template = require.resolve('./lib/loader.js') + '!' + path.resolve(context, template); diff --git a/spec/basic.spec.js b/spec/basic.spec.js index 2734515d..d0a28a3b 100644 --- a/spec/basic.spec.js +++ b/spec/basic.spec.js @@ -214,6 +214,22 @@ describe('HtmlWebpackPlugin', () => { ['