html-webpack-plugin 5.0.0-beta.4 → 5.1.0

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/CHANGELOG.md CHANGED
@@ -2,6 +2,48 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [5.1.0](https://github.com/jantimon/html-webpack-plugin/compare/v5.0.0...v5.1.0) (2021-02-12)
6
+
7
+
8
+ ### Features
9
+
10
+ * omit html tag attribute with null/undefined/false value ([aa6e78d](https://github.com/jantimon/html-webpack-plugin/commit/aa6e78d1430c17d9cf05550b2c9f73a9a0c0166c)), closes [#1598](https://github.com/jantimon/html-webpack-plugin/issues/1598)
11
+
12
+ ## [5.0.0](https://github.com/jantimon/html-webpack-plugin/compare/v4.5.1...v5.0.0) (2021-02-03)
13
+
14
+
15
+ ### ⚠ BREAKING CHANGES
16
+
17
+ * Drop support for `webpack` 4 and `node` <= 10 - For older webpack or node versions please use `html-webpack-plugin` 4.x
18
+ * Entry javascript resources are now beeing loaded deferred in the `<head>` tag to improve the page load performance by default - You can set the `scriptLoading` option to `'blocking'` to keep the previous behaviour
19
+ * Setting publicPath to `''` (an empty string) will no longer calculate a relative path from the html file to the assets anymore - You can set the `publicPath` option to `'auto'` to keep the previous behaviour
20
+ * Plugins for `html-webpack-plugin` which add additional assetTags should provide a `meta` attribute
21
+ * Drop support for `appcache-webpack-plugin`
22
+
23
+ ### Features
24
+
25
+ * drop `webpack` 4 and `node` <= 10 support to make use of the latest APIs ([b7a9e8f](https://github.com/jantimon/html-webpack-plugin/commit/b7a9e8f2a3c146cfec8f5c42888abd6aa0cde0b9))
26
+ * use the new webpack 5 APIs and create html files during the new `webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS` compilation stage ([8964bc4](https://github.com/jantimon/html-webpack-plugin/commit/8964bc4182e41807a564d3000217a40bc5f93ad2), [b6895cb](https://github.com/jantimon/html-webpack-plugin/commit/b6895cb5b85b1e6e850f638470cf9b839d421516), [a97234e](https://github.com/jantimon/html-webpack-plugin/commit/a97234ead5ea2dbba07a6e6a70c5ddb6a5a3c288), [1b59e09](https://github.com/jantimon/html-webpack-plugin/commit/1b59e0944f561b264f11847ef245c9fc3f05b80f), [4fca596](https://github.com/jantimon/html-webpack-plugin/commit/4fca5965315c49f6706812d9fdf6c7284d23d75b), [ed64a6b](https://github.com/jantimon/html-webpack-plugin/commit/ed64a6b35fe9cdbc610e9b766700f3b2fc2b8e4c), [86245db](https://github.com/jantimon/html-webpack-plugin/commit/86245db670a9b3bdd0e2aba9f2031745a98434c7), [50b3bec](https://github.com/jantimon/html-webpack-plugin/commit/50b3bec51a43289d6d1b4e1e6439560eb791576f), [c697725](https://github.com/jantimon/html-webpack-plugin/commit/c697725e9f4dd990bd4b7927bbfa7b826d2f36f2))
27
+ * allow generating one file per chunk with the new `'[name]'` placeholder for the `filename` option ([cd5bd2a](https://github.com/jantimon/html-webpack-plugin/commit/cd5bd2afc902bbe5a5ceec4756ef634a26aa1332), [3d9ff48](https://github.com/jantimon/html-webpack-plugin/commit/3d9ff48543d04d9f7c3440bfefb43751775a9e81))
28
+ * the `filename` option can now be a function ([c5beb4b](https://github.com/jantimon/html-webpack-plugin/commit/c5beb4bd16e4916b5355c300abebf9d7d3c587da))
29
+ * add support for `'auto'` public paths inside templates ([a059fcf](https://github.com/jantimon/html-webpack-plugin/commit/a059fcf32d94aaaa738359cedce0b0e4af68f0de), [b09b439](https://github.com/jantimon/html-webpack-plugin/commit/b09b439f50ecb75994acde2eb2967ad690ff1cf0))
30
+ * use defer as default script loading mechanism ([35b6b87](https://github.com/jantimon/html-webpack-plugin/commit/35b6b878db17f0f5704a187b336a14fdd58cedfc))
31
+ * allow to set publicPath to an empty string `''` ([5ea7de4](https://github.com/jantimon/html-webpack-plugin/commit/5ea7de4ba271813835be700316c8a1763b205d2d))
32
+ * improve typings ([197ddd8](https://github.com/jantimon/html-webpack-plugin/commit/197ddd88f39a2e6e70863b6fed2385d33043d137))
33
+ * provide public path to the alterAssetTagGroups hook ([1b54dfb](https://github.com/jantimon/html-webpack-plugin/commit/1b54dfbd62c0d0df10dd3d2be9937626142d518f))
34
+ * provide public path to the alterAssetTags hook ([b754626](https://github.com/jantimon/html-webpack-plugin/commit/b75462653d11803a428b1d29479e259c3010163f))
35
+ * use `thisCompilation` in child compiler for faster builds ([1d59e9a](https://github.com/jantimon/html-webpack-plugin/commit/1d59e9a71ddba1429168c42569a7bd9bdd363f4f))
36
+ * export new major in static property ([8b692bd](https://github.com/jantimon/html-webpack-plugin/commit/8b692bd7cc0b75ddf55f47da317eed9bd19dab91))
37
+ * reduce dependencies ([8c28aaa](https://github.com/jantimon/html-webpack-plugin/commit/8c28aaa2bed5a7147b397fef3801cfe8fb5c34b9), [56e633f](https://github.com/jantimon/html-webpack-plugin/commit/56e633fcb90909c2bbedbd63590ecaa825d8b31f))
38
+
39
+
40
+ ### Bug Fixes
41
+
42
+ * emit files on every build to work properly with plugins like the
43
+ clean-webpack-plugin ([6b3d087](https://github.com/jantimon/html-webpack-plugin/commit/6b3d087cf17f63b596c298d70a42a7462dd0f881))
44
+ * generate html files even if no webpack entry exists ([2693dfa](https://github.com/jantimon/html-webpack-plugin/commit/2693dfaf4c94625eab86afadfd0e4d8822092d6b))
45
+ * keep binary format when adding assets ([7e2b208](https://github.com/jantimon/html-webpack-plugin/commit/7e2b208634e26299c509e0c6b3189e01e4c3d3df)), closes [#1537](https://github.com/jantimon/html-webpack-plugin/issues/1537)
46
+
5
47
  ### [4.5.1](https://github.com/jantimon/html-webpack-plugin/compare/v4.5.0...v4.5.1) (2021-01-03)
6
48
 
7
49
 
package/README.md CHANGED
@@ -88,6 +88,8 @@ The `html-webpack-plugin` provides [hooks](https://github.com/jantimon/html-webp
88
88
  * [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
89
89
  * [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
90
  * [html-webpack-skip-assets-plugin](https://github.com/swimmadude66/html-webpack-skip-assets-plugin) Skip adding certain output files to the html file. Built as a drop-in replacement for [html-webpack-exclude-assets-plugin](https://www.npmjs.com/package/html-webpack-exclude-assets-plugin) and works with newer [html-webpack-plugin](https://github.com/jantimon/html-webpack-plugin) versions
91
+ * [html-webpack-inject-preload](https://github.com/principalstudio/html-webpack-inject-preload) allows to add preload links &lt;link rel='preload'> anywhere you want.
92
+
91
93
 
92
94
 
93
95
  <h2 align="center">Usage</h2>
@@ -148,7 +150,7 @@ Allowed values are as follows:
148
150
  |**`templateParameters`**|`{Boolean\|Object\|Function}`| `false`| Allows to overwrite the parameters used in the template - see [example](https://github.com/jantimon/html-webpack-plugin/tree/master/examples/template-parameters) |
149
151
  |**`inject`**|`{Boolean\|String}`|`true`|`true \|\| 'head' \|\| 'body' \|\| false` Inject all assets into the given `template` or `templateContent`. When passing `'body'` all javascript resources will be placed at the bottom of the body element. `'head'` will place the scripts in the head element. Passing `true` will add it to the head/body depending on the `scriptLoading` option. Passing `false` will disable automatic injections. - see the [inject:false example](https://github.com/jantimon/html-webpack-plugin/tree/master/examples/custom-insertion-position)|
150
152
  |**`publicPath`**|`{String\|'auto'}`|`'auto'`|The publicPath used for script and link tags|
151
- |**`scriptLoading`**|`{'blocking'\|'defer'}`|`'blocking'`| Modern browsers support non blocking javascript loading (`'defer'`) to improve the page startup performance. |
153
+ |**`scriptLoading`**|`{'blocking'\|'defer'}`|`'defer'`| Modern browsers support non blocking javascript loading (`'defer'`) to improve the page startup performance. |
152
154
  |**`favicon`**|`{String}`|``|Adds the given favicon path to the output HTML|
153
155
  |**`meta`**|`{Object}`|`{}`|Allows to inject `meta`-tags. E.g. `meta: {viewport: 'width=device-width, initial-scale=1, shrink-to-fit=no'}`|
154
156
  |**`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`|
@@ -366,6 +368,7 @@ and the following options:
366
368
  ```js
367
369
  {
368
370
  collapseWhitespace: true,
371
+ keepClosingSlash: true,
369
372
  removeComments: true,
370
373
  removeRedundantAttributes: true,
371
374
  removeScriptTypeAttributes: true,
@@ -518,6 +521,7 @@ about which values are passed.
518
521
  styles: Array<HtmlTagObject>,
519
522
  meta: Array<HtmlTagObject>,
520
523
  },
524
+ publicPath: string,
521
525
  outputName: string,
522
526
  plugin: HtmlWebpackPlugin
523
527
  }>
@@ -529,6 +533,7 @@ about which values are passed.
529
533
  AsyncSeriesWaterfallHook<{
530
534
  headTags: Array<HtmlTagObject | HtmlTagObject>,
531
535
  bodyTags: Array<HtmlTagObject | HtmlTagObject>,
536
+ publicPath: string,
532
537
  outputName: string,
533
538
  plugin: HtmlWebpackPlugin
534
539
  }>
@@ -665,5 +670,5 @@ This project uses the [semistandard code style](https://github.com/Flet/semistan
665
670
  [deps]: https://david-dm.org/jantimon/html-webpack-plugin.svg
666
671
  [deps-url]: https://david-dm.org/jantimon/html-webpack-plugin
667
672
 
668
- [tests]: http://img.shields.io/travis/jantimon/html-webpack-plugin.svg
669
- [tests-url]: https://travis-ci.org/jantimon/html-webpack-plugin
673
+ [tests]: https://github.com/jantimon/html-webpack-plugin/workflows/CI/badge.svg
674
+ [tests-url]: https://github.com/jantimon/html-webpack-plugin/actions?query=workflow%3ACI
package/index.js CHANGED
@@ -91,7 +91,8 @@ class HtmlWebpackPlugin {
91
91
  : (entryName) => userOptionFilename.replace(/\[name\]/g, entryName);
92
92
 
93
93
  /** output filenames for the given entry names */
94
- const outputFileNames = new Set(Object.keys(compiler.options.entry).map(filenameFunction));
94
+ const entryNames = Object.keys(compiler.options.entry);
95
+ const outputFileNames = new Set((entryNames.length ? entryNames : ['main']).map(filenameFunction));
95
96
 
96
97
  /** Option for every entry point */
97
98
  const entryOptions = Array.from(outputFileNames).map((filename) => ({
@@ -297,6 +298,7 @@ function hookIntoCompiler (compiler, options, plugin) {
297
298
  ]
298
299
  },
299
300
  outputName: childCompilationOutputName,
301
+ publicPath: htmlPublicPath,
300
302
  plugin: plugin
301
303
  }))
302
304
  .then(({ assetTags }) => {
@@ -310,6 +312,7 @@ function hookIntoCompiler (compiler, options, plugin) {
310
312
  headTags: assetGroups.headTags,
311
313
  bodyTags: assetGroups.bodyTags,
312
314
  outputName: childCompilationOutputName,
315
+ publicPath: htmlPublicPath,
313
316
  plugin: plugin
314
317
  });
315
318
  });
@@ -714,6 +717,7 @@ function hookIntoCompiler (compiler, options, plugin) {
714
717
  return jsAssets.map(scriptAsset => ({
715
718
  tagName: 'script',
716
719
  voidTag: false,
720
+ meta: { plugin: 'html-webpack-plugin' },
717
721
  attributes: {
718
722
  defer: options.scriptLoading !== 'blocking',
719
723
  src: scriptAsset
@@ -730,6 +734,7 @@ function hookIntoCompiler (compiler, options, plugin) {
730
734
  return cssAssets.map(styleAsset => ({
731
735
  tagName: 'link',
732
736
  voidTag: true,
737
+ meta: { plugin: 'html-webpack-plugin' },
733
738
  attributes: {
734
739
  href: styleAsset,
735
740
  rel: 'stylesheet'
@@ -752,6 +757,7 @@ function hookIntoCompiler (compiler, options, plugin) {
752
757
  return [{
753
758
  tagName: 'base',
754
759
  voidTag: true,
760
+ meta: { plugin: 'html-webpack-plugin' },
755
761
  attributes: (typeof baseOption === 'string') ? {
756
762
  href: baseOption
757
763
  } : baseOption
@@ -794,6 +800,7 @@ function hookIntoCompiler (compiler, options, plugin) {
794
800
  return {
795
801
  tagName: 'meta',
796
802
  voidTag: true,
803
+ meta: { plugin: 'html-webpack-plugin' },
797
804
  attributes: metaTagAttributes
798
805
  };
799
806
  });
@@ -811,6 +818,7 @@ function hookIntoCompiler (compiler, options, plugin) {
811
818
  return [{
812
819
  tagName: 'link',
813
820
  voidTag: true,
821
+ meta: { plugin: 'html-webpack-plugin' },
814
822
  attributes: {
815
823
  rel: 'icon',
816
824
  href: faviconPath
package/lib/hooks.js CHANGED
@@ -32,6 +32,7 @@ const AsyncSeriesWaterfallHook = require('tapable').AsyncSeriesWaterfallHook;
32
32
  styles: Array<HtmlTagObject>,
33
33
  meta: Array<HtmlTagObject>,
34
34
  },
35
+ publicPath: string,
35
36
  outputName: string,
36
37
  plugin: HtmlWebpackPlugin
37
38
  }>,
@@ -39,6 +40,7 @@ const AsyncSeriesWaterfallHook = require('tapable').AsyncSeriesWaterfallHook;
39
40
  AsyncSeriesWaterfallHook<{
40
41
  headTags: Array<HtmlTagObject | HtmlTagObject>,
41
42
  bodyTags: Array<HtmlTagObject | HtmlTagObject>,
43
+ publicPath: string,
42
44
  outputName: string,
43
45
  plugin: HtmlWebpackPlugin
44
46
  }>,
package/lib/html-tags.js CHANGED
@@ -25,12 +25,12 @@ const voidTags = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'k
25
25
  * A tag element according to the htmlWebpackPlugin object notation
26
26
  *
27
27
  * @param xhtml {boolean}
28
- * Wether the generated html should add closing slashes to be xhtml compliant
28
+ * Whether the generated html should add closing slashes to be xhtml compliant
29
29
  */
30
30
  function htmlTagObjectToString (tagDefinition, xhtml) {
31
31
  const attributes = Object.keys(tagDefinition.attributes || {})
32
32
  .filter(function (attributeName) {
33
- return tagDefinition.attributes[attributeName] !== false;
33
+ return tagDefinition.attributes[attributeName] === '' || tagDefinition.attributes[attributeName];
34
34
  })
35
35
  .map(function (attributeName) {
36
36
  if (tagDefinition.attributes[attributeName] === true) {
@@ -49,18 +49,22 @@ function htmlTagObjectToString (tagDefinition, xhtml) {
49
49
  * @param {string} tagName
50
50
  * the name of the tag e.g. 'div'
51
51
  *
52
- * @param {{[attributeName: string]: string|boolean}} [attributes]
52
+ * @param {{[attributeName: string]: string|boolean|null|undefined}} [attributes]
53
53
  * tag attributes e.g. `{ 'class': 'example', disabled: true }`
54
54
  *
55
55
  * @param {string} [innerHTML]
56
56
  *
57
+ * @param {{[attributeName: string]: string|boolean|null|undefined}} [meta]
58
+ * meta information about the tag e.g. `{ 'plugin': 'html-webpack-plugin' }`
59
+ *
57
60
  * @returns {HtmlTagObject}
58
61
  */
59
- function createHtmlTagObject (tagName, attributes, innerHTML) {
62
+ function createHtmlTagObject (tagName, attributes, innerHTML, meta) {
60
63
  return {
61
64
  tagName: tagName,
62
65
  voidTag: voidTags.indexOf(tagName) !== -1,
63
66
  attributes: attributes || {},
67
+ meta: meta || {},
64
68
  innerHTML: innerHTML
65
69
  };
66
70
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "html-webpack-plugin",
3
- "version": "5.0.0-beta.4",
3
+ "version": "5.1.0",
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)",
@@ -46,7 +46,7 @@
46
46
  "standard-version": "9.1.0",
47
47
  "style-loader": "2.0.0",
48
48
  "typescript": "4.1.3",
49
- "webpack": "^5.10.0",
49
+ "webpack": "^5.20.0",
50
50
  "webpack-recompilation-simulator": "3.2.0",
51
51
  "webpack-cli": "4.2.0"
52
52
  },
@@ -59,7 +59,7 @@
59
59
  "tapable": "^2.0.0"
60
60
  },
61
61
  "peerDependencies": {
62
- "webpack": "^5.1.2"
62
+ "webpack": "^5.20.0"
63
63
  },
64
64
  "keywords": [
65
65
  "webpack",
package/typings.d.ts CHANGED
@@ -209,6 +209,7 @@ declare namespace HtmlWebpackPlugin {
209
209
  styles: HtmlTagObject[];
210
210
  meta: HtmlTagObject[];
211
211
  };
212
+ publicPath: string,
212
213
  outputName: string;
213
214
  plugin: HtmlWebpackPlugin;
214
215
  }>;
@@ -217,6 +218,7 @@ declare namespace HtmlWebpackPlugin {
217
218
  headTags: HtmlTagObject[];
218
219
  bodyTags: HtmlTagObject[];
219
220
  outputName: string;
221
+ publicPath: string,
220
222
  plugin: HtmlWebpackPlugin;
221
223
  }>;
222
224
 
@@ -261,7 +263,7 @@ declare namespace HtmlWebpackPlugin {
261
263
  * E.g. `{'disabled': true, 'value': 'demo'}`
262
264
  */
263
265
  attributes: {
264
- [attributeName: string]: string | boolean;
266
+ [attributeName: string]: string | boolean | null | undefined;
265
267
  };
266
268
  /**
267
269
  * The tag name e.g. `'div'`
@@ -276,5 +278,13 @@ declare namespace HtmlWebpackPlugin {
276
278
  * @see https://www.w3.org/TR/html5/syntax.html#void-elements
277
279
  */
278
280
  voidTag: boolean;
281
+ /**
282
+ * Meta information about the tag
283
+ * E.g. `{'plugin': 'html-webpack-plugin'}`
284
+ */
285
+ meta: {
286
+ plugin?: string,
287
+ [metaAttributeName: string]: any;
288
+ };
279
289
  }
280
290
  }