html-webpack-plugin 4.0.0-beta.2 → 4.0.0-beta.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -77,6 +77,7 @@ The `html-webpack-plugin` provides [hooks](https://github.com/jantimon/html-webp
77
77
  * [html-webpack-include-assets-plugin](https://github.com/jharris4/html-webpack-include-assets-plugin) for including lists of js or css file paths (such as those copied by the copy-webpack-plugin).
78
78
  * [script-ext-html-webpack-plugin](https://github.com/numical/script-ext-html-webpack-plugin) to add `async`, `defer` or `module` attributes to your `<script>` elements, or even inline them
79
79
  * [style-ext-html-webpack-plugin](https://github.com/numical/style-ext-html-webpack-plugin) to convert your `<link>`s to external stylesheets into `<style>` elements containing internal CSS
80
+ * [html-webpack-injector](https://github.com/thearchitgarg/html-webpack-injector) to inject chunks in `head` or `body` (different locations ) of same html document.
80
81
  * [resource-hints-webpack-plugin](https://github.com/jantimon/resource-hints-webpack-plugin) to add resource hints for faster initial page loads using `<link rel='preload'>` and `<link rel='prefetch'>`
81
82
  * [preload-webpack-plugin](https://github.com/GoogleChrome/preload-webpack-plugin) for automatically wiring up asynchronous (and other types) of JavaScript chunks using `<link rel='preload'>` helping with lazy-loading
82
83
  * [link-media-html-webpack-plugin](https://github.com/yaycmyk/link-media-html-webpack-plugin) allows for injected stylesheet `<link />` tags to have their media attribute set automatically; useful for providing specific desktop/mobile/print etc. stylesheets that the browser will conditionally download
@@ -84,9 +85,9 @@ The `html-webpack-plugin` provides [hooks](https://github.com/jantimon/html-webp
84
85
  * [html-webpack-inline-style-plugin](https://github.com/djaax/html-webpack-inline-style-plugin) for inlining styles to HTML elements using [juice](https://github.com/Automattic/juice). Useful for email generation automatisation.
85
86
  * [html-webpack-exclude-empty-assets-plugin](https://github.com/KnisterPeter/html-webpack-exclude-empty-assets-plugin) removes empty assets from being added to the html. This fixes some problems with extract-text-plugin with webpack 4.
86
87
  * [webpack-concat-plugin](https://github.com/hxlniada/webpack-concat-plugin) for concat and uglify files that needn't to be webpack bundles(for legacy files) and inject to html-webpack-plugin.
87
- * [html-webpack-link-type-plugin](https://github.com/steadyapp/html-webpack-link-type-plugin) adds a configurable mimetype to resources injected as links (such as adding type="text/css" to external stylesheets) for compatability with "strict mode".
88
-
88
+ * [html-webpack-link-type-plugin](https://github.com/steadyapp/html-webpack-link-type-plugin) adds a configurable mimetype to resources injected as links (such as adding type="text/css" to external stylesheets) for compatibility with "strict mode".
89
89
  * [csp-html-webpack-plugin](https://github.com/slackhq/csp-html-webpack-plugin) to add [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy) meta tags to the HTML output
90
+ * [webpack-nomodule-plugin](https://github.com/swimmadude66/webpack-nomodule-plugin) allows you to add a `nomodule` attribute to specific injected scripts, which prevents the scripts from being loaded by newer browsers. Good for limiting loads of polyfills.
90
91
 
91
92
 
92
93
  <h2 align="center">Usage</h2>
@@ -128,7 +129,7 @@ This will generate a file `dist/index.html` containing the following
128
129
 
129
130
  If you have multiple `webpack` entry points, they will all be included with `script` tags in the generated HTML.
130
131
 
131
- If you have any CSS assets in webpack's output (for example, CSS extracted with the [ExtractTextPlugin](https://github.com/webpack/extract-text-webpack-plugin))
132
+ If you have any CSS assets in webpack's output (for example, CSS extracted with the [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin))
132
133
  then these will be included with `<link>` tags in the HTML head.
133
134
 
134
135
  If you have plugins that make use of it, `html-webpack-plugin` should be ordered first before any of the integrated plugins.
@@ -140,21 +141,22 @@ Allowed values are as follows
140
141
 
141
142
  |Name|Type|Default|Description|
142
143
  |:--:|:--:|:-----:|:----------|
143
- |**[`title`](#)**|`{String}`|`Webpack App`|The title to use for the generated HTML document|
144
- |**[`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`)|
145
- |**[`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|
146
- |**[`templateParameters`](#)**|`{Boolean\|Object\|Function}`|``| Allows to overwrite the parameters used in the template |
147
- |**[`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|
148
- |**[`favicon`](#)**|`{String}`|``|Adds the given favicon path to the output HTML|
149
- |**[`meta`](#)**|`{Object}`|`{}`|Allows to inject `meta`-tags. E.g. `meta: {viewport: 'width=device-width, initial-scale=1, shrink-to-fit=no'}`|
150
- |**[`minify`](#)**|`{Boolean\|Object}`|`true` if `mode` is `'production'`, otherwise `false`|Controls if and in what ways the output should be minified. See [minification](#minification) below for more details.|
151
- |**[`hash`](#)**|`{Boolean}`|`false`|If `true` then append a unique `webpack` compilation hash to all included scripts and CSS files. This is useful for cache busting|
152
- |**[`cache`](#)**|`{Boolean}`|`true`|Emit the file only if it was changed|
153
- |**[`showErrors`](#)**|`{Boolean}`|`true`|Errors details will be written into the HTML page|
154
- |**[`chunks`](#)**|`{?}`|`?`|Allows you to add only some chunks (e.g only the unit-test chunk)|
144
+ |**`title`**|`{String}`|`Webpack App`|The title to use for the generated HTML document|
145
+ |**`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`)|
146
+ |**`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|
147
+ |**`templateParameters`**|`{Boolean\|Object\|Function}`|``| Allows to overwrite the parameters used in the template |
148
+ |**`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|
149
+ |**`favicon`**|`{String}`|``|Adds the given favicon path to the output HTML|
150
+ |**`meta`**|`{Object}`|`{}`|Allows to inject `meta`-tags. E.g. `meta: {viewport: 'width=device-width, initial-scale=1, shrink-to-fit=no'}`|
151
+ |**`base`**|`{Object\|String\|false}`|`false`|Inject a [`base`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base) tag. E.g. `base: "https://example.com/path/page.html`|
152
+ |**`minify`**|`{Boolean\|Object}`|`true` if `mode` is `'production'`, otherwise `false`|Controls if and in what ways the output should be minified. See [minification](#minification) below for more details.|
153
+ |**`hash`**|`{Boolean}`|`false`|If `true` then append a unique `webpack` compilation hash to all included scripts and CSS files. This is useful for cache busting|
154
+ |**`cache`**|`{Boolean}`|`true`|Emit the file only if it was changed|
155
+ |**`showErrors`**|`{Boolean}`|`true`|Errors details will be written into the HTML page|
156
+ |**`chunks`**|`{?}`|`?`|Allows you to add only some chunks (e.g only the unit-test chunk)|
155
157
  |**[`chunksSortMode`](#plugins)**|`{String\|Function}`|`auto`|Allows to control how chunks should be sorted before they are included to the HTML. Allowed values are `'none' \| 'auto' \| 'dependency' \| 'manual' \| {Function}`|
156
- |**[`excludeChunks`](#)**|`{Array.<string>}`|``|Allows you to skip some chunks (e.g don't add the unit-test chunk)|
157
- |**[`xhtml`](#)**|`{Boolean}`|`false`|If `true` render the `link` tags as self-closing (XHTML compliant)|
158
+ |**`excludeChunks`**|`{Array.<string>}`|``|Allows you to skip some chunks (e.g don't add the unit-test chunk)|
159
+ |**`xhtml`**|`{Boolean}`|`false`|If `true` render the `link` tags as self-closing (XHTML compliant)|
158
160
 
159
161
  Here's an example webpack config illustrating how to use these options
160
162
 
@@ -205,11 +207,13 @@ your own template. The easiest way is to use the `template` option and pass a cu
205
207
  The html-webpack-plugin will automatically inject all necessary CSS, JS, manifest
206
208
  and favicon files into the markup.
207
209
 
210
+ Details of other template loaders are [documented here](https://github.com/jantimon/html-webpack-plugin/blob/master/docs/template-option.md).
211
+
208
212
  ```js
209
213
  plugins: [
210
214
  new HtmlWebpackPlugin({
211
215
  title: 'Custom template',
212
- // Load a custom template (lodash by default see the FAQ for details)
216
+ // Load a custom template (lodash by default)
213
217
  template: 'index.html'
214
218
  })
215
219
  ]
@@ -336,7 +340,7 @@ and the following options:
336
340
  To use custom [html-minifier options](https://github.com/kangax/html-minifier#options-quick-reference)
337
341
  pass an object to `minify` instead. This object will not be merged with the defaults above.
338
342
 
339
- To disable minifcations during production mode set the `minfy` option to `false`.
343
+ To disable minification during production mode set the `minify` option to `false`.
340
344
 
341
345
  ### Meta Tags
342
346
 
@@ -354,10 +358,12 @@ To add those use a key/value pair:
354
358
  ```js
355
359
  plugins: [
356
360
  new HtmlWebpackPlugin({
357
- 'viewport': 'width=device-width, initial-scale=1, shrink-to-fit=no',
358
- // Will generate: <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
359
- 'theme-color': '#4285f4'
360
- // Will generate: <meta name="theme-color" content="#4285f4">
361
+ 'meta': {
362
+ 'viewport': 'width=device-width, initial-scale=1, shrink-to-fit=no',
363
+ // Will generate: <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
364
+ 'theme-color': '#4285f4'
365
+ // Will generate: <meta name="theme-color" content="#4285f4">
366
+ }
361
367
  })
362
368
  ]
363
369
  ```
@@ -383,6 +389,63 @@ plugins: [
383
389
  ]
384
390
  ```
385
391
 
392
+ ### Base Tag
393
+
394
+ When the `base` option is used,
395
+ html-webpack-plugin will inject a [base tag](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base).
396
+ By default, a base tag will not be injected.
397
+
398
+ The following two are identical and will both insert `<base href="http://example.com/some/page.html">`:
399
+
400
+ ```js
401
+ new HtmlWebpackPlugin({
402
+ 'base': 'http://example.com/some/page.html'
403
+ })
404
+ ```
405
+
406
+ ```js
407
+ new HtmlWebpackPlugin({
408
+ 'base': { 'href': 'http://example.com/some/page.html' }
409
+ })
410
+ ```
411
+
412
+ The `target` can be specified with the corresponding key:
413
+
414
+ ```js
415
+ new HtmlWebpackPlugin({
416
+ 'base': {
417
+ 'href': 'http://example.com/some/page.html',
418
+ 'target': '_blank'
419
+ }
420
+ })
421
+ ```
422
+
423
+ which will inject the element `<base href="http://example.com/some/page.html" target="_blank">`.
424
+
425
+ ### Long Term Caching
426
+
427
+ For long term caching add `contenthash/templatehash` to the filename.
428
+
429
+ **Example:**
430
+
431
+ ```js
432
+ plugins: [
433
+ new HtmlWebpackPlugin({
434
+ filename: 'index.[contenthash].html'
435
+ })
436
+ ]
437
+ ```
438
+
439
+ `contenthash/templatehash` is the hash of the content of the output file.
440
+
441
+ Optionally, You can configure like `[<hashType>:contenthash:<digestType>:<length>]`
442
+
443
+ * `hashType` - one of `sha1`, `md5`, `sha256`, `sha512` or any other node.js supported hash type
444
+ * `digestType` - one of `hex`, `base26`, `base32`, `base36`, `base49`, `base52`, `base58`, `base62`, `base64`
445
+ * `maxlength` - maximum length of the generated hash in chars
446
+
447
+ **Defaults:** `[md5:contenthash:hex:9999]`
448
+
386
449
  ### Events
387
450
 
388
451
  To allow other [plugins](https://github.com/webpack/docs/wiki/plugins) to alter the HTML this plugin executes
@@ -471,7 +534,8 @@ Example implementation: [webpack-subresource-integrity](https://www.npmjs.com/pa
471
534
  ```js
472
535
  // If your plugin is direct dependent to the html webpack plugin:
473
536
  const HtmlWebpackPlugin = require('html-webpack-plugin');
474
- // If your plugins is using html-webpack-plugin you can use https://github.com/tallesl/node-safe-require
537
+ // If your plugin is using html-webpack-plugin as an optional dependency
538
+ // you can use https://github.com/tallesl/node-safe-require instead:
475
539
  const HtmlWebpackPlugin = require('safe-require')('html-webpack-plugin');
476
540
 
477
541
  class MyPlugin {
@@ -479,7 +543,7 @@ class MyPlugin {
479
543
  compiler.hooks.compilation.tap('MyPlugin', (compilation) => {
480
544
  console.log('The compiler is starting a new compilation...')
481
545
 
482
- // Staic Plugin interface |compilation |HOOK NAME | register listener
546
+ // Static Plugin interface |compilation |HOOK NAME | register listener
483
547
  HtmlWebpackPlugin.getHooks(compilation).beforeEmit.tapAsync(
484
548
  'MyPlugin', // <-- Set a meaningful name here for stacktraces
485
549
  (data, cb) => {
package/index.js CHANGED
@@ -1,8 +1,9 @@
1
1
  // @ts-check
2
2
  // Import types
3
- /* eslint-disable */
4
- /// <reference path="./typings.d.ts" />
5
- /* eslint-enable */
3
+ /** @typedef {import("./typings").HtmlTagObject} HtmlTagObject */
4
+ /** @typedef {import("./typings").Options} HtmlWebpackOptions */
5
+ /** @typedef {import("./typings").ProcessedOptions} ProcessedHtmlWebpackOptions */
6
+ /** @typedef {import("./typings").TemplateParameter} TemplateParameter */
6
7
  /** @typedef {import("webpack/lib/Compiler.js")} WebpackCompiler */
7
8
  /** @typedef {import("webpack/lib/Compilation.js")} WebpackCompilation */
8
9
  'use strict';
@@ -28,16 +29,16 @@ const fsReadFileAsync = promisify(fs.readFile);
28
29
 
29
30
  class HtmlWebpackPlugin {
30
31
  /**
31
- * @param {Partial<HtmlWebpackPluginOptions>} [options]
32
+ * @param {HtmlWebpackOptions} [options]
32
33
  */
33
34
  constructor (options) {
34
- /** @type {Partial<HtmlWebpackPluginOptions>} */
35
+ /** @type {HtmlWebpackOptions} */
35
36
  const userOptions = options || {};
36
37
 
37
38
  // Default options
38
- /** @type {HtmlWebpackPluginOptions} */
39
+ /** @type {ProcessedHtmlWebpackOptions} */
39
40
  const defaultOptions = {
40
- template: path.join(__dirname, 'default_index.ejs'),
41
+ template: 'auto',
41
42
  templateContent: false,
42
43
  templateParameters: templateParametersGenerator,
43
44
  filename: 'index.html',
@@ -45,18 +46,19 @@ class HtmlWebpackPlugin {
45
46
  inject: true,
46
47
  compile: true,
47
48
  favicon: false,
48
- minify: undefined,
49
+ minify: 'auto',
49
50
  cache: true,
50
51
  showErrors: true,
51
52
  chunks: 'all',
52
53
  excludeChunks: [],
53
54
  chunksSortMode: 'auto',
54
55
  meta: {},
56
+ base: false,
55
57
  title: 'Webpack App',
56
58
  xhtml: false
57
59
  };
58
60
 
59
- /** @type {HtmlWebpackPluginOptions} */
61
+ /** @type {ProcessedHtmlWebpackOptions} */
60
62
  this.options = Object.assign(defaultOptions, userOptions);
61
63
 
62
64
  // Default metaOptions if no template is provided
@@ -111,7 +113,8 @@ class HtmlWebpackPlugin {
111
113
  const isProductionLikeMode = compiler.options.mode === 'production' || !compiler.options.mode;
112
114
 
113
115
  const minify = this.options.minify;
114
- if (minify === true || (minify === undefined && isProductionLikeMode)) {
116
+ if (minify === true || (minify === 'auto' && isProductionLikeMode)) {
117
+ /** @type { import('html-minifier').Options } */
115
118
  this.options.minify = {
116
119
  // https://github.com/kangax/html-minifier#options-quick-reference
117
120
  collapseWhitespace: true,
@@ -216,11 +219,12 @@ class HtmlWebpackPlugin {
216
219
  // Turn the js and css paths into grouped HtmlTagObjects
217
220
  const assetTagGroupsPromise = assetsPromise
218
221
  // And allow third-party-plugin authors to reorder and change the assetTags before they are grouped
219
- .then(({assets}) => getHtmlWebpackPluginHooks(compilation).alterAssetTags.promise({
222
+ .then(({ assets }) => getHtmlWebpackPluginHooks(compilation).alterAssetTags.promise({
220
223
  assetTags: {
221
224
  scripts: self.generatedScriptTags(assets.js),
222
225
  styles: self.generateStyleTags(assets.css),
223
226
  meta: [
227
+ ...self.generateBaseTag(self.options.base),
224
228
  ...self.generatedMetaTags(self.options.meta),
225
229
  ...self.generateFaviconTags(assets.favicon)
226
230
  ]
@@ -228,7 +232,7 @@ class HtmlWebpackPlugin {
228
232
  outputName: childCompilationOutputName,
229
233
  plugin: self
230
234
  }))
231
- .then(({assetTags}) => {
235
+ .then(({ assetTags }) => {
232
236
  // Inject scripts to body unless it set explictly to head
233
237
  const scriptTarget = self.options.inject === 'head' ? 'head' : 'body';
234
238
  // Group assets to `head` and `body` tag arrays
@@ -263,17 +267,17 @@ class HtmlWebpackPlugin {
263
267
  const injectedHtmlPromise = Promise.all([assetTagGroupsPromise, templateExectutionPromise])
264
268
  // Allow plugins to change the html before assets are injected
265
269
  .then(([assetTags, html]) => {
266
- const pluginArgs = {html, headTags: assetTags.headTags, bodyTags: assetTags.bodyTags, plugin: self, outputName: childCompilationOutputName};
270
+ const pluginArgs = { html, headTags: assetTags.headTags, bodyTags: assetTags.bodyTags, plugin: self, outputName: childCompilationOutputName };
267
271
  return getHtmlWebpackPluginHooks(compilation).afterTemplateExecution.promise(pluginArgs);
268
272
  })
269
- .then(({html, headTags, bodyTags}) => {
270
- return self.postProcessHtml(html, assets, {headTags, bodyTags});
273
+ .then(({ html, headTags, bodyTags }) => {
274
+ return self.postProcessHtml(html, assets, { headTags, bodyTags });
271
275
  });
272
276
 
273
277
  const emitHtmlPromise = injectedHtmlPromise
274
278
  // Allow plugins to change the html after assets are injected
275
279
  .then((html) => {
276
- const pluginArgs = {html, plugin: self, outputName: childCompilationOutputName};
280
+ const pluginArgs = { html, plugin: self, outputName: childCompilationOutputName };
277
281
  return getHtmlWebpackPluginHooks(compilation).beforeEmit.promise(pluginArgs)
278
282
  .then(result => result.html);
279
283
  })
@@ -329,8 +333,8 @@ class HtmlWebpackPlugin {
329
333
  // To extract the result during the evaluation this part has to be removed.
330
334
  source = source.replace('var HTML_WEBPACK_PLUGIN_RESULT =', '');
331
335
  const template = this.options.template.replace(/^.+!/, '').replace(/\?.+$/, '');
332
- const vmContext = vm.createContext(_.extend({HTML_WEBPACK_PLUGIN: true, require: require}, global));
333
- const vmScript = new vm.Script(source, {filename: template});
336
+ const vmContext = vm.createContext(_.extend({ HTML_WEBPACK_PLUGIN: true, require: require }, global));
337
+ const vmScript = new vm.Script(source, { filename: template });
334
338
  // Evaluate code and cast to string
335
339
  let newSource;
336
340
  try {
@@ -381,7 +385,7 @@ class HtmlWebpackPlugin {
381
385
  /**
382
386
  * This function renders the actual html by executing the template function
383
387
  *
384
- * @param {(templatePArameters) => string | Promise<string>} templateFunction
388
+ * @param {(templateParameters) => string | Promise<string>} templateFunction
385
389
  * @param {{
386
390
  publicPath: string,
387
391
  js: Array<string>,
@@ -433,7 +437,7 @@ class HtmlWebpackPlugin {
433
437
  const htmlAfterInjection = this.options.inject
434
438
  ? this.injectAssetsIntoHtml(html, assets, assetTags)
435
439
  : html;
436
- const htmlAfterMinification = this.options.minify
440
+ const htmlAfterMinification = typeof this.options.minify === 'object'
437
441
  ? require('html-minifier').minify(htmlAfterInjection, this.options.minify)
438
442
  : htmlAfterInjection;
439
443
  return Promise.resolve(htmlAfterMinification);
@@ -524,21 +528,6 @@ class HtmlWebpackPlugin {
524
528
  return assets.js.length && assets.js.every((assetPath) => /\.hot-update\.js$/.test(assetPath));
525
529
  }
526
530
 
527
- /**
528
- * Return true if PATH is an absolute url path, otherwise false
529
- *
530
- * @param {string | undefined} path
531
- */
532
- isAbsolutePath (path) {
533
- if (typeof path === 'undefined' || path === '') return false;
534
- // If the path start with '/'
535
- if (path.indexOf('/') === 0) return true;
536
- // If the path contain the '://' scheme
537
- if (path.indexOf('://') !== -1) return true;
538
-
539
- return false;
540
- }
541
-
542
531
  /**
543
532
  * The htmlWebpackPluginAssets extracts the asset information of a webpack compilation
544
533
  * for all given entry names
@@ -557,13 +546,15 @@ class HtmlWebpackPlugin {
557
546
 
558
547
  /**
559
548
  * @type {string} the configured public path to the asset root
560
- * if the absolute path publicPath is set in the current webpack config use it otherwise
549
+ * if a path publicPath is set in the current webpack config use it otherwise
561
550
  * fallback to a realtive path
562
551
  */
563
- let publicPath = this.isAbsolutePath(compilation.options.output.publicPath)
564
- // If the absolute path is set in the publicPath use it
565
- ? compilation.mainTemplate.getPublicPath({hash: compilationHash})
566
- // If publicPath was a relative path get the realtive path
552
+ const webpackPublicPath = compilation.mainTemplate.getPublicPath({ hash: compilationHash });
553
+ const isPublicPathDefined = webpackPublicPath.trim() !== '';
554
+ let publicPath = isPublicPathDefined
555
+ // If a hard coded public path exists use it
556
+ ? webpackPublicPath
557
+ // If no public path was set get a relative url path
567
558
  : path.relative(path.resolve(compilation.options.output.path, path.dirname(childCompilationOutputName)), compilation.options.output.path)
568
559
  .split(path.sep).join('/');
569
560
 
@@ -583,7 +574,7 @@ class HtmlWebpackPlugin {
583
574
  const assets = {
584
575
  // The public path
585
576
  publicPath: publicPath,
586
- // Will contain all js files
577
+ // Will contain all js and mjs files
587
578
  js: [],
588
579
  // Will contain all css files
589
580
  css: [],
@@ -598,9 +589,9 @@ class HtmlWebpackPlugin {
598
589
  assets.manifest = this.appendHash(assets.manifest, compilationHash);
599
590
  }
600
591
 
601
- // Extract paths to .js and .css files from the current compilation
592
+ // Extract paths to .js, .mjs and .css files from the current compilation
602
593
  const entryPointPublicPathMap = {};
603
- const extensionRegexp = /\.(css|js)(\?|$)/;
594
+ const extensionRegexp = /\.(css|js|mjs)(\?|$)/;
604
595
  for (let i = 0; i < entryNames.length; i++) {
605
596
  const entryName = entryNames[i];
606
597
  const entryPointFiles = compilation.entrypoints.get(entryName).getFiles();
@@ -617,7 +608,7 @@ class HtmlWebpackPlugin {
617
608
 
618
609
  entryPointPublicPaths.forEach((entryPointPublicPath) => {
619
610
  const extMatch = extensionRegexp.exec(entryPointPublicPath);
620
- // Skip if the public path is not a .css or .js file
611
+ // Skip if the public path is not a .css, .mjs or .js file
621
612
  if (!extMatch) {
622
613
  return;
623
614
  }
@@ -627,8 +618,8 @@ class HtmlWebpackPlugin {
627
618
  return;
628
619
  }
629
620
  entryPointPublicPathMap[entryPointPublicPath] = true;
630
- // ext will contain .js or .css
631
- const ext = extMatch[1];
621
+ // ext will contain .js or .css, because .mjs recognizes as .js
622
+ const ext = extMatch[1] === 'mjs' ? 'js' : extMatch[1];
632
623
  assets[ext].push(entryPointPublicPath);
633
624
  });
634
625
  }
@@ -641,7 +632,7 @@ class HtmlWebpackPlugin {
641
632
  *
642
633
  * @param {string|false} faviconFilePath
643
634
  * @param {WebpackCompilation} compilation
644
- * @parma {string} publicPath
635
+ * @param {string} publicPath
645
636
  * @returns {Promise<string|undefined>}
646
637
  */
647
638
  getFaviconPublicPath (faviconFilePath, compilation, publicPath) {
@@ -724,6 +715,28 @@ class HtmlWebpackPlugin {
724
715
  }));
725
716
  }
726
717
 
718
+ /**
719
+ * Generate an optional base tag
720
+ * @param { false
721
+ | string
722
+ | {[attributeName: string]: string} // attributes e.g. { href:"http://example.com/page.html" target:"_blank" }
723
+ } baseOption
724
+ * @returns {Array<HtmlTagObject>}
725
+ */
726
+ generateBaseTag (baseOption) {
727
+ if (baseOption === false) {
728
+ return [];
729
+ } else {
730
+ return [{
731
+ tagName: 'base',
732
+ voidTag: true,
733
+ attributes: (typeof baseOption === 'string') ? {
734
+ href: baseOption
735
+ } : baseOption
736
+ }];
737
+ }
738
+ }
739
+
727
740
  /**
728
741
  * Generate all meta tags for the given meta configuration
729
742
  * @param {false | {
@@ -890,11 +903,17 @@ class HtmlWebpackPlugin {
890
903
  /**
891
904
  * Helper to return the absolute template path with a fallback loader
892
905
  * @param {string} template
893
- * The path to the tempalate e.g. './index.html'
906
+ * The path to the template e.g. './index.html'
894
907
  * @param {string} context
895
908
  * The webpack base resolution path for relative paths e.g. process.cwd()
896
909
  */
897
910
  getFullTemplatePath (template, context) {
911
+ if (template === 'auto') {
912
+ template = path.resolve(context, 'src/index.ejs');
913
+ if (!fs.existsSync(template)) {
914
+ template = path.join(__dirname, 'default_index.ejs');
915
+ }
916
+ }
898
917
  // If the template doesn't use a loader use the lodash template loader
899
918
  if (template.indexOf('!') === -1) {
900
919
  template = require.resolve('./lib/loader.js') + '!' + path.resolve(context, template);
@@ -933,8 +952,8 @@ class HtmlWebpackPlugin {
933
952
  headTags: HtmlTagObject[],
934
953
  bodyTags: HtmlTagObject[]
935
954
  }} assetTags
936
- * @param {HtmlWebpackPluginOptions} options
937
- * @returns {HtmlWebpackPluginTemplateParameter}
955
+ * @param {ProcessedHtmlWebpackOptions} options
956
+ * @returns {TemplateParameter}
938
957
  */
939
958
  function templateParametersGenerator (compilation, assets, assetTags, options) {
940
959
  const xhtml = options.xhtml;
package/lib/compiler.js CHANGED
@@ -119,18 +119,6 @@ class HtmlWebpackChildCompiler {
119
119
  new LibraryTemplatePlugin('HTML_WEBPACK_PLUGIN_RESULT', 'var').apply(childCompiler);
120
120
  new LoaderTargetPlugin('node').apply(childCompiler);
121
121
 
122
- // Fix for "Uncaught TypeError: __webpack_require__(...) is not a function"
123
- // Hot module replacement requires that every child compiler has its own
124
- // cache. @see https://github.com/ampedandwired/html-webpack-plugin/pull/179
125
- childCompiler.hooks.compilation.tap('HtmlWebpackPlugin', compilation => {
126
- if (compilation.cache) {
127
- if (!compilation.cache[compilerName]) {
128
- compilation.cache[compilerName] = {};
129
- }
130
- compilation.cache = compilation.cache[compilerName];
131
- }
132
- });
133
-
134
122
  // Add all templates
135
123
  this.templates.forEach((template, index) => {
136
124
  new SingleEntryPlugin(childCompiler.context, template, `HtmlWebpackPlugin_${index}`).apply(childCompiler);
@@ -145,7 +133,7 @@ class HtmlWebpackChildCompiler {
145
133
  : [];
146
134
  // Extract file dependencies
147
135
  if (entries) {
148
- this.fileDependencies = extractFileDependenciesFilesFromCompilation(entries);
136
+ this.fileDependencies = Array.from(childCompilation.fileDependencies);
149
137
  }
150
138
  // Reject the promise if the childCompilation contains error
151
139
  if (childCompilation && childCompilation.errors && childCompilation.errors.length) {
@@ -209,21 +197,6 @@ function extractHelperFilesFromCompilation (mainCompilation, childCompilation, f
209
197
  return helperContents;
210
198
  }
211
199
 
212
- /**
213
- * Return all file dependencies from the given set of entries.
214
- * @param {WebpackChunk[]} entries
215
- * @returns {string[]}
216
- */
217
- function extractFileDependenciesFilesFromCompilation (entries) {
218
- const fileDependencies = new Map();
219
- entries.forEach((entry) => {
220
- entry.entryModule.buildInfo.fileDependencies.forEach((fileDependency) => {
221
- fileDependencies.set(fileDependency, true);
222
- });
223
- });
224
- return Array.from(fileDependencies.keys());
225
- }
226
-
227
200
  /**
228
201
  * @type {WeakMap<WebpackCompiler, HtmlWebpackChildCompiler>}}
229
202
  */
package/lib/errors.js CHANGED
@@ -18,7 +18,14 @@ module.exports = function (err, context) {
18
18
  return JSON.stringify(this.toHtml());
19
19
  },
20
20
  toString: function () {
21
- return prettyError.render(err).replace(/webpack:\/\/\/\./g, context);
21
+ try {
22
+ return prettyError.render(err).replace(/webpack:\/\/\/\./g, context);
23
+ } catch (e) {
24
+ // This can sometimes fail. We don't know why, but returning the
25
+ // original error is better than returning the error thrown by
26
+ // pretty-error.
27
+ return err;
28
+ }
22
29
  }
23
30
  };
24
31
  };
package/lib/hooks.js CHANGED
@@ -1,7 +1,5 @@
1
1
  // @ts-check
2
- /* eslint-disable */
3
- /// <reference path="../typings.d.ts" />
4
- /* eslint-enable */
2
+ /** @typedef {import("../typings").Hooks} HtmlWebpackPluginHooks */
5
3
  'use strict';
6
4
  /**
7
5
  * This file provides access to all public htmlWebpackPlugin hooks
@@ -12,10 +10,9 @@
12
10
 
13
11
  const AsyncSeriesWaterfallHook = require('tapable').AsyncSeriesWaterfallHook;
14
12
 
15
- // The following typedef holds the API definition for all available hooks
16
- // to allow easier access when using ts-check or typescript inside plugins
17
- /** @typedef {{
18
-
13
+ // The following is the API definition for all available hooks
14
+ // For the TypeScript definition, see the Hooks type in typings.d.ts
15
+ /**
19
16
  beforeAssetTagGeneration:
20
17
  AsyncSeriesWaterfallHook<{
21
18
  assets: {
@@ -28,7 +25,6 @@ const AsyncSeriesWaterfallHook = require('tapable').AsyncSeriesWaterfallHook;
28
25
  outputName: string,
29
26
  plugin: HtmlWebpackPlugin
30
27
  }>,
31
-
32
28
  alterAssetTags:
33
29
  AsyncSeriesWaterfallHook<{
34
30
  assetTags: {
@@ -39,7 +35,6 @@ const AsyncSeriesWaterfallHook = require('tapable').AsyncSeriesWaterfallHook;
39
35
  outputName: string,
40
36
  plugin: HtmlWebpackPlugin
41
37
  }>,
42
-
43
38
  alterAssetTagGroups:
44
39
  AsyncSeriesWaterfallHook<{
45
40
  headTags: Array<HtmlTagObject | HtmlTagObject>,
@@ -47,7 +42,6 @@ const AsyncSeriesWaterfallHook = require('tapable').AsyncSeriesWaterfallHook;
47
42
  outputName: string,
48
43
  plugin: HtmlWebpackPlugin
49
44
  }>,
50
-
51
45
  afterTemplateExecution:
52
46
  AsyncSeriesWaterfallHook<{
53
47
  html: string,
@@ -56,22 +50,18 @@ const AsyncSeriesWaterfallHook = require('tapable').AsyncSeriesWaterfallHook;
56
50
  outputName: string,
57
51
  plugin: HtmlWebpackPlugin,
58
52
  }>,
59
-
60
53
  beforeEmit:
61
54
  AsyncSeriesWaterfallHook<{
62
55
  html: string,
63
56
  outputName: string,
64
57
  plugin: HtmlWebpackPlugin,
65
58
  }>,
66
-
67
59
  afterEmit:
68
60
  AsyncSeriesWaterfallHook<{
69
61
  outputName: string,
70
62
  plugin: HtmlWebpackPlugin
71
- }>,
72
-
73
- }} HtmlWebpackPluginHooks
74
- */
63
+ }>
64
+ */
75
65
 
76
66
  /**
77
67
  * @type {WeakMap<WebpackCompilation, HtmlWebpackPluginHooks>}}
package/lib/html-tags.js CHANGED
@@ -1,7 +1,5 @@
1
1
  // @ts-check
2
- /* eslint-disable */
3
- /// <reference path="../typings.d.ts" />
4
- /* eslint-enable */
2
+ /** @typedef {import("../typings").HtmlTagObject} HtmlTagObject */
5
3
  /**
6
4
  * @file
7
5
  * This file provides to helper to create html as a object repesentation as
package/lib/loader.js CHANGED
@@ -21,11 +21,12 @@ module.exports = function (source) {
21
21
  return source;
22
22
  }
23
23
 
24
- // The following part renders the template with lodash as aminimalistic loader
24
+ // The following part renders the template with lodash as a minimalistic loader
25
25
  //
26
26
  const template = _.template(source, _.defaults(options, { interpolate: /<%=([\s\S]+?)%>/g, variable: 'data' }));
27
- // Require !!lodash - using !! will disable all loaders (e.g. babel)
28
- return 'var _ = require(' + loaderUtils.stringifyRequest(this, '!!' + require.resolve('lodash')) + ');' +
27
+ // Use __non_webpack_require__ to enforce using the native nodejs require
28
+ // during template execution
29
+ return 'var _ = __non_webpack_require__(' + JSON.stringify(require.resolve('lodash')) + ');' +
29
30
  'module.exports = function (templateParams) { with(templateParams) {' +
30
31
  // Execute the lodash template
31
32
  'return (' + template.source + ')();' +
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "html-webpack-plugin",
3
- "version": "4.0.0-beta.2",
3
+ "version": "4.0.0-beta.8",
4
4
  "license": "MIT",
5
5
  "description": "Simplifies creation of HTML files to serve your webpack bundles",
6
6
  "author": "Jan Nicklas <j.nicklas@me.com> (https://github.com/jantimon)",
7
7
  "main": "index.js",
8
+ "types": "typings.d.ts",
8
9
  "files": [
9
10
  "lib/",
10
11
  "index.js",
@@ -27,34 +28,35 @@
27
28
  ]
28
29
  },
29
30
  "devDependencies": {
31
+ "@types/html-minifier": "3.5.3",
30
32
  "@types/loader-utils": "1.1.3",
31
- "@types/node": "10.11.4",
33
+ "@types/node": "11.13.9",
32
34
  "@types/tapable": "1.0.4",
33
- "appcache-webpack-plugin": "^1.4.0",
34
- "commitizen": "3.0.2",
35
- "css-loader": "^1.0.0",
35
+ "appcache-webpack-plugin": "1.4.0",
36
+ "commitizen": "3.1.1",
37
+ "css-loader": "2.1.1",
36
38
  "cz-conventional-changelog": "2.1.0",
37
- "dir-compare": "1.4.0",
38
- "file-loader": "^2.0.0",
39
- "html-loader": "^0.5.5",
40
- "jest": "23.6.0",
41
- "mini-css-extract-plugin": "^0.4.3",
39
+ "dir-compare": "1.7.2",
40
+ "file-loader": "3.0.1",
41
+ "html-loader": "0.5.5",
42
+ "jest": "24.7.1",
43
+ "mini-css-extract-plugin": "0.6.0",
42
44
  "pug": "2.0.3",
43
45
  "pug-loader": "2.4.0",
44
- "rimraf": "^2.6.2",
45
- "semistandard": "12.0.1",
46
- "standard-version": "^4.4.0",
47
- "style-loader": "^0.23.0",
48
- "typescript": "^2.9.2",
49
- "webpack": "^4.20.2",
50
- "webpack-recompilation-simulator": "^3.0.0"
46
+ "rimraf": "2.6.3",
47
+ "semistandard": "13.0.1",
48
+ "standard-version": "5.0.2",
49
+ "style-loader": "0.23.1",
50
+ "typescript": "3.5.2",
51
+ "webpack": "4.35.2",
52
+ "webpack-recompilation-simulator": "3.0.0"
51
53
  },
52
54
  "dependencies": {
53
- "html-minifier": "^3.5.20",
54
- "loader-utils": "^1.1.0",
55
+ "html-minifier": "^4.0.0",
56
+ "loader-utils": "^1.2.3",
55
57
  "lodash": "^4.17.11",
56
58
  "pretty-error": "^2.1.1",
57
- "tapable": "^1.1.0",
59
+ "tapable": "^1.1.3",
58
60
  "util.promisify": "1.0.0"
59
61
  },
60
62
  "peerDependencies": {
package/typings.d.ts CHANGED
@@ -1,139 +1,236 @@
1
+ import { AsyncSeriesWaterfallHook } from "tapable";
2
+ import { Compiler } from 'webpack';
3
+ import { Options as HtmlMinifierOptions } from "html-minifier";
1
4
 
2
- /**
3
- * The plugin options
4
- */
5
- interface HtmlWebpackPluginOptions {
5
+ export = HtmlWebpackPlugin;
6
+
7
+ declare class HtmlWebpackPlugin {
8
+ constructor(options?: HtmlWebpackPlugin.Options);
9
+
10
+ apply(compiler: Compiler): void;
11
+ }
12
+
13
+ declare namespace HtmlWebpackPlugin {
14
+ type MinifyOptions = HtmlMinifierOptions;
15
+
16
+ interface Options extends Partial<ProcessedOptions> {}
17
+
18
+ /**
19
+ * The plugin options after adding default values
20
+ */
21
+ interface ProcessedOptions {
6
22
  /**
7
- * The title to use for the generated HTML document
23
+ * Emit the file only if it was changed.
24
+ * Default: `true`.
8
25
  */
9
- title: string,
26
+ cache: boolean;
10
27
  /**
11
- * The `webpack` require path to the template.
12
- * @see https://github.com/jantimon/html-webpack-plugin/blob/master/docs/template-option.md
28
+ * List all entries which should be injected
13
29
  */
14
- template: string,
30
+ chunks: "all" | string[];
15
31
  /**
16
- * Allow to use a html string instead of reading from a file
32
+ * Allows to control how chunks should be sorted before they are included to the html.
33
+ * Default: `'auto'`.
17
34
  */
18
- templateContent:
19
- false // Use the template option instead to load a file
20
- | string
21
- | Promise<string>,
35
+ chunksSortMode:
36
+ | "auto"
37
+ | "manual"
38
+ | (((entryNameA: string, entryNameB: string) => number));
22
39
  /**
23
- * Allows to overwrite the parameters used in the template
40
+ * List all entries which should not be injeccted
24
41
  */
25
- templateParameters:
26
- false // Pass an empty object to the template function
27
- | ((compilation: any, assets, assetTags: { headTags: Array<HtmlTagObject>, bodyTags: Array<HtmlTagObject> }, options: HtmlWebpackPluginOptions) => {[option: string]: any})
28
- | ((compilation: any, assets, assetTags: { headTags: Array<HtmlTagObject>, bodyTags: Array<HtmlTagObject> }, options: HtmlWebpackPluginOptions) => Promise<{[option: string]: any}>)
29
- | {[option: string]: any}
42
+ excludeChunks: string[];
43
+ /**
44
+ * Path to the favicon icon
45
+ */
46
+ favicon: false | string;
30
47
  /**
31
48
  * The file to write the HTML to.
32
49
  * Defaults to `index.html`.
33
50
  * Supports subdirectories eg: `assets/admin.html`
34
51
  */
35
- filename: string,
52
+ filename: string;
36
53
  /**
37
54
  * If `true` then append a unique `webpack` compilation hash to all included scripts and CSS files.
38
55
  * This is useful for cache busting
39
56
  */
40
- hash: boolean,
57
+ hash: boolean;
41
58
  /**
42
59
  * Inject all assets into the given `template` or `templateContent`.
43
60
  */
44
- inject: false // Don't inject scripts
45
- | true // Inject scripts into body
46
- | 'body' // Inject scripts into body
47
- | 'head' // Inject scripts into head
61
+ inject:
62
+ | false // Don't inject scripts
63
+ | true // Inject scripts into body
64
+ | "body" // Inject scripts into body
65
+ | "head"; // Inject scripts into head
48
66
  /**
49
- * Path to the favicon icon
67
+ * Inject meta tags
50
68
  */
51
- favicon: false | string,
69
+ meta:
70
+ | false // Disable injection
71
+ | {
72
+ [name: string]:
73
+ | string
74
+ | false // name content pair e.g. {viewport: 'width=device-width, initial-scale=1, shrink-to-fit=no'}`
75
+ | { [attributeName: string]: string | boolean }; // custom properties e.g. { name:"viewport" content:"width=500, initial-scale=1" }
76
+ };
52
77
  /**
53
- * HTML Minification options
78
+ * HTML Minification options accepts the following valeus:
79
+ * - Set to `false` to disable minifcation
80
+ * - Set to `'auto'` to enable minifcation only for production mode
81
+ * - Set to custom minification according to
54
82
  * @https://github.com/kangax/html-minifier#options-quick-reference
55
83
  */
56
- minify?: boolean | {},
57
- cache: boolean,
84
+ minify: 'auto' | boolean | MinifyOptions;
58
85
  /**
59
86
  * Render errors into the HTML page
60
87
  */
61
- showErrors: boolean,
88
+ showErrors: boolean;
62
89
  /**
63
- * List all entries which should be injected
90
+ * The `webpack` require path to the template.
91
+ * @see https://github.com/jantimon/html-webpack-plugin/blob/master/docs/template-option.md
64
92
  */
65
- chunks: 'all' | string[],
93
+ template: string;
66
94
  /**
67
- * List all entries which should not be injeccted
95
+ * Allow to use a html string instead of reading from a file
68
96
  */
69
- excludeChunks: string[],
70
- chunksSortMode: 'auto' | 'manual' | (((entryNameA: string, entryNameB: string) => number)),
97
+ templateContent:
98
+ | false // Use the template option instead to load a file
99
+ | string
100
+ | Promise<string>;
71
101
  /**
72
- * Inject meta tags
102
+ * Allows to overwrite the parameters used in the template
73
103
  */
74
- meta: false // Disable injection
75
- | {
76
- [name: string]: string|false // name content pair e.g. {viewport: 'width=device-width, initial-scale=1, shrink-to-fit=no'}`
77
- | {[attributeName: string]: string|boolean} // custom properties e.g. { name:"viewport" content:"width=500, initial-scale=1" }
78
- },
104
+ templateParameters:
105
+ | false // Pass an empty object to the template function
106
+ | ((
107
+ compilation: any,
108
+ assets: {
109
+ publicPath: string;
110
+ js: Array<string>;
111
+ css: Array<string>;
112
+ manifest?: string;
113
+ favicon?: string;
114
+ },
115
+ assetTags: {
116
+ headTags: HtmlTagObject[];
117
+ bodyTags: HtmlTagObject[];
118
+ },
119
+ options: ProcessedOptions
120
+ ) => { [option: string]: any } | Promise<{ [option: string]: any }>)
121
+ | { [option: string]: any };
122
+ /**
123
+ * The title to use for the generated HTML document
124
+ */
125
+ title: string;
79
126
  /**
80
127
  * Enforce self closing tags e.g. <link />
81
128
  */
82
- xhtml: boolean
83
-
129
+ xhtml: boolean;
84
130
  /**
85
131
  * In addition to the options actually used by this plugin, you can use this hash to pass arbitrary data through
86
132
  * to your template.
87
133
  */
88
134
  [option: string]: any;
89
- }
135
+ }
90
136
 
91
- /**
92
- * A tag element according to the htmlWebpackPlugin object notation
93
- */
94
- interface HtmlTagObject {
95
- /**
96
- * Attributes of the html tag
97
- * E.g. `{'disabled': true, 'value': 'demo'}`
98
- */
99
- attributes: {
100
- [attributeName: string]: string|boolean
101
- },
102
- /**
103
- * Wether this html must not contain innerHTML
104
- * @see https://www.w3.org/TR/html5/syntax.html#void-elements
105
- */
106
- voidTag: boolean,
107
137
  /**
108
- * The tag name e.g. `'div'`
138
+ * The values which are available during template execution
139
+ *
140
+ * Please keep in mind that the `templateParameter` options allows to change them
109
141
  */
110
- tagName: string,
142
+ interface TemplateParameter {
143
+ compilation: any;
144
+ htmlWebpackPlugin: {
145
+ tags: {
146
+ headTags: HtmlTagObject[];
147
+ bodyTags: HtmlTagObject[];
148
+ };
149
+ files: {
150
+ publicPath: string;
151
+ js: Array<string>;
152
+ css: Array<string>;
153
+ manifest?: string;
154
+ favicon?: string;
155
+ };
156
+ options: Options;
157
+ };
158
+ webpackConfig: any;
159
+ }
160
+
161
+ interface Hooks {
162
+ alterAssetTags: AsyncSeriesWaterfallHook<{
163
+ assetTags: {
164
+ scripts: HtmlTagObject[];
165
+ styles: HtmlTagObject[];
166
+ meta: HtmlTagObject[];
167
+ };
168
+ outputName: string;
169
+ plugin: HtmlWebpackPlugin;
170
+ }>;
171
+
172
+ alterAssetTagGroups: AsyncSeriesWaterfallHook<{
173
+ headTags: HtmlTagObject[];
174
+ bodyTags: HtmlTagObject[];
175
+ outputName: string;
176
+ plugin: HtmlWebpackPlugin;
177
+ }>;
178
+
179
+ afterTemplateExecution: AsyncSeriesWaterfallHook<{
180
+ html: string;
181
+ headTags: HtmlTagObject[];
182
+ bodyTags: HtmlTagObject[];
183
+ outputName: string;
184
+ plugin: HtmlWebpackPlugin;
185
+ }>;
186
+
187
+ beforeAssetTagGeneration: AsyncSeriesWaterfallHook<{
188
+ assets: {
189
+ publicPath: string;
190
+ js: Array<string>;
191
+ css: Array<string>;
192
+ favicon?: string;
193
+ manifest?: string;
194
+ };
195
+ outputName: string;
196
+ plugin: HtmlWebpackPlugin;
197
+ }>;
198
+
199
+ beforeEmit: AsyncSeriesWaterfallHook<{
200
+ html: string;
201
+ outputName: string;
202
+ plugin: HtmlWebpackPlugin;
203
+ }>;
204
+
205
+ afterEmit: AsyncSeriesWaterfallHook<{
206
+ outputName: string;
207
+ plugin: HtmlWebpackPlugin;
208
+ }>;
209
+ }
210
+
111
211
  /**
112
- * Inner HTML The
212
+ * A tag element according to the htmlWebpackPlugin object notation
113
213
  */
114
- innerHTML?: string
115
- }
116
-
117
- /**
118
- * The values which are available during template execution
119
- *
120
- * Please keep in mind that the `templateParameter` options allows to change them
121
- */
122
- interface HtmlWebpackPluginTemplateParameter {
123
- compilation: any,
124
- webpackConfig: any
125
- htmlWebpackPlugin: {
126
- tags: {
127
- headTags: HtmlTagObject[],
128
- bodyTags: HtmlTagObject[]
129
- },
130
- files: {
131
- publicPath: string,
132
- js: Array<string>,
133
- css: Array<string>,
134
- manifest?: string,
135
- favicon?: string
136
- },
137
- options: HtmlWebpackPluginOptions
214
+ interface HtmlTagObject {
215
+ /**
216
+ * Attributes of the html tag
217
+ * E.g. `{'disabled': true, 'value': 'demo'}`
218
+ */
219
+ attributes: {
220
+ [attributeName: string]: string | boolean;
221
+ };
222
+ /**
223
+ * The tag name e.g. `'div'`
224
+ */
225
+ tagName: string;
226
+ /**
227
+ * The inner HTML
228
+ */
229
+ innerHTML?: string;
230
+ /**
231
+ * Whether this html must not contain innerHTML
232
+ * @see https://www.w3.org/TR/html5/syntax.html#void-elements
233
+ */
234
+ voidTag: boolean;
138
235
  }
139
236
  }