html-webpack-plugin 3.0.8 → 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 CHANGED
@@ -2,6 +2,16 @@
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
+
5
15
  <a name="3.0.8"></a>
6
16
  ## [3.0.8](https://github.com/jantimon/html-webpack-plugin/compare/v3.0.7...v3.0.8) (2018-03-22)
7
17
 
package/README.md CHANGED
@@ -110,6 +110,7 @@ Allowed values are as follows
110
110
  |**[`title`](#)**|`{String}`|``|The title to use for the generated HTML document|
111
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`)|
112
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 |
113
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|
114
115
  |**[`favicon`](#)**|`{String}`|``|Adds the given favicon path to the output HTML|
115
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|
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "html-webpack-plugin",
3
- "version": "3.0.8",
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)",