html-webpack-plugin 3.0.5 → 3.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 +40 -0
- package/README.md +41 -17
- package/index.js +31 -10
- package/lib/compiler.js +13 -9
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,46 @@
|
|
|
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
|
+
<a name="3.1.0"></a>
|
|
6
|
+
# [3.1.0](https://github.com/jantimon/html-webpack-plugin/compare/v3.0.8...v3.1.0) (2018-03-22)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Allow to overwrite the templateParameter [#830](https://github.com/jantimon/html-webpack-plugin/issues/830) ([c5e32d3](https://github.com/jantimon/html-webpack-plugin/commit/c5e32d3))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
<a name="3.0.8"></a>
|
|
16
|
+
## [3.0.8](https://github.com/jantimon/html-webpack-plugin/compare/v3.0.7...v3.0.8) (2018-03-22)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Bug Fixes
|
|
20
|
+
|
|
21
|
+
* **compiler:** Fallback to 3.0.7 because of [#900](https://github.com/jantimon/html-webpack-plugin/issues/900) ([05ee29b](https://github.com/jantimon/html-webpack-plugin/commit/05ee29b))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
<a name="3.0.7"></a>
|
|
26
|
+
## [3.0.7](https://github.com/jantimon/html-webpack-plugin/compare/v3.0.6...v3.0.7) (2018-03-19)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Bug Fixes
|
|
30
|
+
|
|
31
|
+
* **compiler:** Set single entry name [#895](https://github.com/jantimon/html-webpack-plugin/issues/895) ([26dcb98](https://github.com/jantimon/html-webpack-plugin/commit/26dcb98))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
<a name="3.0.6"></a>
|
|
36
|
+
## [3.0.6](https://github.com/jantimon/html-webpack-plugin/compare/v3.0.5...v3.0.6) (2018-03-06)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### Bug Fixes
|
|
40
|
+
|
|
41
|
+
* **hooks:** Call tapable.apply directly [#879](https://github.com/jantimon/html-webpack-plugin/issues/879) ([bcbb036](https://github.com/jantimon/html-webpack-plugin/commit/bcbb036))
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
5
45
|
<a name="3.0.5"></a>
|
|
6
46
|
## [3.0.5](https://github.com/jantimon/html-webpack-plugin/compare/v3.0.2...v3.0.5) (2018-03-06)
|
|
7
47
|
|
package/README.md
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
[![npm][npm]][npm-url]
|
|
2
2
|
[![node][node]][node-url]
|
|
3
|
+

|
|
3
4
|
[![deps][deps]][deps-url]
|
|
4
5
|
[![tests][tests]][tests-url]
|
|
5
|
-
[](#backers)
|
|
7
|
+
[](#sponsors)
|
|
7
8
|
|
|
8
9
|
<div align="center">
|
|
9
10
|
<img width="200" height="200" src="https://worldvectorlogo.com/logos/html5.svg">
|
|
@@ -53,6 +54,7 @@ The `html-webpack-plugin` provides [hooks](https://github.com/jantimon/html-webp
|
|
|
53
54
|
* [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
|
|
54
55
|
* [inline-chunk-manifest-html-webpack-plugin](https://github.com/jouni-kantola/inline-chunk-manifest-html-webpack-plugin) for inlining webpack's chunk manifest. Default extracts manifest and inlines in `<head>`
|
|
55
56
|
* [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.
|
|
57
|
+
* [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.
|
|
56
58
|
|
|
57
59
|
<h2 align="center">Usage</h2>
|
|
58
60
|
|
|
@@ -108,6 +110,7 @@ Allowed values are as follows
|
|
|
108
110
|
|**[`title`](#)**|`{String}`|``|The title to use for the generated HTML document|
|
|
109
111
|
|**[`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`)|
|
|
110
112
|
|**[`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|
|
|
113
|
+
|**[`templateParameters`](#)**|`{Boolean\|Object\|Function}`|``| Allows to overwrite the parameters used in the template |
|
|
111
114
|
|**[`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|
|
|
112
115
|
|**[`favicon`](#)**|`{String}`|``|Adds the given favicon path to the output HTML|
|
|
113
116
|
|**[`minify`](#)**|`{Boolean\|Object}`|`true`|Pass [html-minifier](https://github.com/kangax/html-minifier#options-quick-reference)'s options as object to minify the output|
|
|
@@ -115,7 +118,7 @@ Allowed values are as follows
|
|
|
115
118
|
|**[`cache`](#)**|`{Boolean}`|`true`|Emit the file only if it was changed|
|
|
116
119
|
|**[`showErrors`](#)**|`{Boolean}`|`true`|Errors details will be written into the HTML page|
|
|
117
120
|
|**[`chunks`](#)**|`{?}`|`?`|Allows you to add only some chunks (e.g only the unit-test chunk)|
|
|
118
|
-
|**[`chunksSortMode`](#plugins)**|`{String
|
|
121
|
+
|**[`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}`|
|
|
119
122
|
|**[`excludeChunks`](#)**|`{String}`|``|Allows you to skip some chunks (e.g don't add the unit-test chunk)|
|
|
120
123
|
|**[`xhtml`](#)**|`{Boolean}`|`false`|If `true` render the `link` tags as self-closing (XHTML compliant)|
|
|
121
124
|
|
|
@@ -143,7 +146,7 @@ Here's an example webpack config illustrating how to use these options
|
|
|
143
146
|
To generate more than one HTML file, declare the plugin more than
|
|
144
147
|
once in your plugins array
|
|
145
148
|
|
|
146
|
-
**webpack.
|
|
149
|
+
**webpack.config.js**
|
|
147
150
|
```js
|
|
148
151
|
{
|
|
149
152
|
entry: 'index.js',
|
|
@@ -330,15 +333,6 @@ plugins: [
|
|
|
330
333
|
|
|
331
334
|
Note that the callback must be passed the HtmlWebpackPluginData in order to pass this onto any other plugins listening on the same `html-webpack-plugin-before-html-processing` event
|
|
332
335
|
|
|
333
|
-
<h2 align="center">Contribution</h2>
|
|
334
|
-
|
|
335
|
-
You're free to contribute to this project by submitting [issues](https://github.com/jantimon/html-webpack-plugin/issues) and/or [pull requests](https://github.com/jantimon/html-webpack-plugin/pulls). This project is test-driven, so keep in mind that every change and new feature should be covered by tests.
|
|
336
|
-
|
|
337
|
-
This project uses the [semistandard code style](https://github.com/Flet/semistandard).
|
|
338
|
-
|
|
339
|
-
Before running the tests, make sure to execute `yarn link` and `yarn link html-webpack-plugin` (or the `npm` variant of this).
|
|
340
|
-
|
|
341
|
-
|
|
342
336
|
<h2 align="center">Maintainers</h2>
|
|
343
337
|
|
|
344
338
|
<table>
|
|
@@ -373,8 +367,38 @@ Before running the tests, make sure to execute `yarn link` and `yarn link html-w
|
|
|
373
367
|
[tests]: http://img.shields.io/travis/jantimon/html-webpack-plugin.svg
|
|
374
368
|
[tests-url]: https://travis-ci.org/jantimon/html-webpack-plugin
|
|
375
369
|
|
|
376
|
-
[cover]: https://img.shields.io/codecov/c/github/jantimon/html-webpack-plugin.svg
|
|
377
|
-
[cover-url]: https://codecov.io/gh/jantimon/html-webpack-plugin
|
|
378
370
|
|
|
379
|
-
|
|
380
|
-
|
|
371
|
+
## Contributors
|
|
372
|
+
|
|
373
|
+
This project exists thanks to all the people who contribute.
|
|
374
|
+
|
|
375
|
+
You're free to contribute to this project by submitting [issues](https://github.com/jantimon/html-webpack-plugin/issues) and/or [pull requests](https://github.com/jantimon/html-webpack-plugin/pulls). This project is test-driven, so keep in mind that every change and new feature should be covered by tests.
|
|
376
|
+
|
|
377
|
+
This project uses the [semistandard code style](https://github.com/Flet/semistandard).
|
|
378
|
+
|
|
379
|
+
<a href="https://github.com/jantimon/html-webpack-plugin/graphs/contributors"><img src="https://opencollective.com/html-webpack-plugin/contributors.svg?width=890&button=false" /></a>
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
## Backers
|
|
383
|
+
|
|
384
|
+
Thank you to all our backers! 🙏 [Become a backer](https://opencollective.com/html-webpack-plugin#backer)
|
|
385
|
+
|
|
386
|
+
<a href="https://opencollective.com/html-webpack-plugin#backers" target="_blank"><img src="https://opencollective.com/html-webpack-plugin/backers.svg?width=890"></a>
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
## Sponsors
|
|
390
|
+
|
|
391
|
+
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor](https://opencollective.com/html-webpack-plugin#sponsor)
|
|
392
|
+
|
|
393
|
+
<a href="https://opencollective.com/html-webpack-plugin/sponsor/0/website" target="_blank"><img src="https://opencollective.com/html-webpack-plugin/sponsor/0/avatar.svg"></a>
|
|
394
|
+
<a href="https://opencollective.com/html-webpack-plugin/sponsor/1/website" target="_blank"><img src="https://opencollective.com/html-webpack-plugin/sponsor/1/avatar.svg"></a>
|
|
395
|
+
<a href="https://opencollective.com/html-webpack-plugin/sponsor/2/website" target="_blank"><img src="https://opencollective.com/html-webpack-plugin/sponsor/2/avatar.svg"></a>
|
|
396
|
+
<a href="https://opencollective.com/html-webpack-plugin/sponsor/3/website" target="_blank"><img src="https://opencollective.com/html-webpack-plugin/sponsor/3/avatar.svg"></a>
|
|
397
|
+
<a href="https://opencollective.com/html-webpack-plugin/sponsor/4/website" target="_blank"><img src="https://opencollective.com/html-webpack-plugin/sponsor/4/avatar.svg"></a>
|
|
398
|
+
<a href="https://opencollective.com/html-webpack-plugin/sponsor/5/website" target="_blank"><img src="https://opencollective.com/html-webpack-plugin/sponsor/5/avatar.svg"></a>
|
|
399
|
+
<a href="https://opencollective.com/html-webpack-plugin/sponsor/6/website" target="_blank"><img src="https://opencollective.com/html-webpack-plugin/sponsor/6/avatar.svg"></a>
|
|
400
|
+
<a href="https://opencollective.com/html-webpack-plugin/sponsor/7/website" target="_blank"><img src="https://opencollective.com/html-webpack-plugin/sponsor/7/avatar.svg"></a>
|
|
401
|
+
<a href="https://opencollective.com/html-webpack-plugin/sponsor/8/website" target="_blank"><img src="https://opencollective.com/html-webpack-plugin/sponsor/8/avatar.svg"></a>
|
|
402
|
+
<a href="https://opencollective.com/html-webpack-plugin/sponsor/9/website" target="_blank"><img src="https://opencollective.com/html-webpack-plugin/sponsor/9/avatar.svg"></a>
|
|
403
|
+
|
|
404
|
+
|
package/index.js
CHANGED
|
@@ -19,6 +19,7 @@ class HtmlWebpackPlugin {
|
|
|
19
19
|
// Default options
|
|
20
20
|
this.options = _.extend({
|
|
21
21
|
template: path.join(__dirname, 'default_index.ejs'),
|
|
22
|
+
templateParameters: templateParametersGenerator,
|
|
22
23
|
filename: 'index.html',
|
|
23
24
|
hash: false,
|
|
24
25
|
inject: true,
|
|
@@ -253,25 +254,29 @@ class HtmlWebpackPlugin {
|
|
|
253
254
|
: Promise.reject('The loader "' + this.options.template + '" didn\'t return html.');
|
|
254
255
|
}
|
|
255
256
|
|
|
257
|
+
/**
|
|
258
|
+
* Generate the template parameters for the template function
|
|
259
|
+
*/
|
|
260
|
+
getTemplateParameters (compilation, assets) {
|
|
261
|
+
if (typeof this.options.templateParameters === 'function') {
|
|
262
|
+
return this.options.templateParameters(compilation, assets, this.options);
|
|
263
|
+
}
|
|
264
|
+
if (typeof this.options.templateParameters === 'object') {
|
|
265
|
+
return this.options.templateParameters;
|
|
266
|
+
}
|
|
267
|
+
return {};
|
|
268
|
+
}
|
|
269
|
+
|
|
256
270
|
/**
|
|
257
271
|
* Html post processing
|
|
258
272
|
*
|
|
259
273
|
* Returns a promise
|
|
260
274
|
*/
|
|
261
275
|
executeTemplate (templateFunction, chunks, assets, compilation) {
|
|
262
|
-
const self = this;
|
|
263
276
|
return Promise.resolve()
|
|
264
277
|
// Template processing
|
|
265
278
|
.then(() => {
|
|
266
|
-
const templateParams =
|
|
267
|
-
compilation: compilation,
|
|
268
|
-
webpack: compilation.getStats().toJson(),
|
|
269
|
-
webpackConfig: compilation.options,
|
|
270
|
-
htmlWebpackPlugin: {
|
|
271
|
-
files: assets,
|
|
272
|
-
options: self.options
|
|
273
|
-
}
|
|
274
|
-
};
|
|
279
|
+
const templateParams = this.getTemplateParameters(compilation, assets);
|
|
275
280
|
let html = '';
|
|
276
281
|
try {
|
|
277
282
|
html = templateFunction(templateParams);
|
|
@@ -684,4 +689,20 @@ function trainCaseToCamelCase (word) {
|
|
|
684
689
|
return word.replace(/-([\w])/g, (match, p1) => p1.toUpperCase());
|
|
685
690
|
}
|
|
686
691
|
|
|
692
|
+
/**
|
|
693
|
+
* The default for options.templateParameter
|
|
694
|
+
* Generate the template parameters
|
|
695
|
+
*/
|
|
696
|
+
function templateParametersGenerator (compilation, assets, options) {
|
|
697
|
+
return {
|
|
698
|
+
compilation: compilation,
|
|
699
|
+
webpack: compilation.getStats().toJson(),
|
|
700
|
+
webpackConfig: compilation.options,
|
|
701
|
+
htmlWebpackPlugin: {
|
|
702
|
+
files: assets,
|
|
703
|
+
options: options
|
|
704
|
+
}
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
|
|
687
708
|
module.exports = HtmlWebpackPlugin;
|
package/lib/compiler.js
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
*
|
|
6
6
|
*/
|
|
7
7
|
'use strict';
|
|
8
|
-
const _ = require('lodash');
|
|
9
8
|
const path = require('path');
|
|
10
9
|
const NodeTemplatePlugin = require('webpack/lib/node/NodeTemplatePlugin');
|
|
11
10
|
const NodeTargetPlugin = require('webpack/lib/node/NodeTargetPlugin');
|
|
@@ -37,20 +36,25 @@ module.exports.compileTemplate = function compileTemplate (template, context, ou
|
|
|
37
36
|
publicPath: compilation.outputOptions.publicPath
|
|
38
37
|
};
|
|
39
38
|
// Store the result of the parent compilation before we start the child compilation
|
|
40
|
-
const assetsBeforeCompilation =
|
|
39
|
+
const assetsBeforeCompilation = Object.assign({}, compilation.assets[outputOptions.filename]);
|
|
41
40
|
// Create an additional child compiler which takes the template
|
|
42
41
|
// and turns it into an Node.JS html factory.
|
|
43
42
|
// This allows us to use loaders during the compilation
|
|
44
43
|
const compilerName = getCompilerName(context, outputFilename);
|
|
45
44
|
const childCompiler = compilation.createChildCompiler(compilerName, outputOptions);
|
|
46
45
|
childCompiler.context = context;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
46
|
+
new NodeTemplatePlugin(outputOptions).apply(childCompiler);
|
|
47
|
+
new NodeTargetPlugin().apply(childCompiler);
|
|
48
|
+
new LibraryTemplatePlugin('HTML_WEBPACK_PLUGIN_RESULT', 'var').apply(childCompiler);
|
|
49
|
+
|
|
50
|
+
// Using undefined as name for the SingleEntryPlugin causes a unexpected output as described in
|
|
51
|
+
// https://github.com/jantimon/html-webpack-plugin/issues/895
|
|
52
|
+
// Using a string as a name for the SingleEntryPlugin causes problems with HMR as described in
|
|
53
|
+
// https://github.com/jantimon/html-webpack-plugin/issues/900
|
|
54
|
+
// Until the HMR issue is fixed we keep the ugly output:
|
|
55
|
+
new SingleEntryPlugin(this.context, template, undefined).apply(childCompiler);
|
|
56
|
+
|
|
57
|
+
new LoaderTargetPlugin('node').apply(childCompiler);
|
|
54
58
|
|
|
55
59
|
// Fix for "Uncaught TypeError: __webpack_require__(...) is not a function"
|
|
56
60
|
// Hot module replacement requires that every child compiler has its own
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "html-webpack-plugin",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Simplifies creation of HTML files to serve your webpack bundles",
|
|
6
6
|
"author": "Charles Blaxland <charles.blaxland@gmail.com> (https://github.com/ampedandwired)",
|