html-webpack-plugin 3.0.6 → 3.2.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,53 @@
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.2.0"></a>
6
+ # [3.2.0](https://github.com/jantimon/html-webpack-plugin/compare/v3.1.0...v3.2.0) (2018-04-03)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **loader:** Allow to add new template parameters ([f7eac19](https://github.com/jantimon/html-webpack-plugin/commit/f7eac19)), closes [#915](https://github.com/jantimon/html-webpack-plugin/issues/915)
12
+ * **loader:** Use lodash inside the loader directly ([7b4eb7f](https://github.com/jantimon/html-webpack-plugin/commit/7b4eb7f)), closes [#786](https://github.com/jantimon/html-webpack-plugin/issues/786)
13
+
14
+
15
+ ### Features
16
+
17
+ * Add meta tag option ([a7d37ca](https://github.com/jantimon/html-webpack-plugin/commit/a7d37ca))
18
+ * Support node 6.9 ([74a22c4](https://github.com/jantimon/html-webpack-plugin/commit/74a22c4)), closes [#918](https://github.com/jantimon/html-webpack-plugin/issues/918)
19
+
20
+
21
+
22
+ <a name="3.1.0"></a>
23
+ # [3.1.0](https://github.com/jantimon/html-webpack-plugin/compare/v3.0.8...v3.1.0) (2018-03-22)
24
+
25
+
26
+ ### Features
27
+
28
+ * 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))
29
+
30
+
31
+
32
+ <a name="3.0.8"></a>
33
+ ## [3.0.8](https://github.com/jantimon/html-webpack-plugin/compare/v3.0.7...v3.0.8) (2018-03-22)
34
+
35
+
36
+ ### Bug Fixes
37
+
38
+ * **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))
39
+
40
+
41
+
42
+ <a name="3.0.7"></a>
43
+ ## [3.0.7](https://github.com/jantimon/html-webpack-plugin/compare/v3.0.6...v3.0.7) (2018-03-19)
44
+
45
+
46
+ ### Bug Fixes
47
+
48
+ * **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))
49
+
50
+
51
+
5
52
  <a name="3.0.6"></a>
6
53
  ## [3.0.6](https://github.com/jantimon/html-webpack-plugin/compare/v3.0.5...v3.0.6) (2018-03-06)
7
54
 
package/README.md CHANGED
@@ -1,9 +1,10 @@
1
1
  [![npm][npm]][npm-url]
2
2
  [![node][node]][node-url]
3
+ ![npm](https://img.shields.io/npm/dw/html-webpack-plugin.svg)
3
4
  [![deps][deps]][deps-url]
4
5
  [![tests][tests]][tests-url]
5
- [![coverage][cover]][cover-url]
6
- [![chat][chat]][chat-url]
6
+ [![Backers on Open Collective](https://opencollective.com/html-webpack-plugin/backers/badge.svg)](#backers)
7
+ [![Sponsors on Open Collective](https://opencollective.com/html-webpack-plugin/sponsors/badge.svg)](#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,9 @@ 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.
58
+ * [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.
59
+
56
60
 
57
61
  <h2 align="center">Usage</h2>
58
62
 
@@ -108,15 +112,17 @@ Allowed values are as follows
108
112
  |**[`title`](#)**|`{String}`|``|The title to use for the generated HTML document|
109
113
  |**[`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
114
  |**[`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|
115
+ |**[`templateParameters`](#)**|`{Boolean\|Object\|Function}`|``| Allows to overwrite the parameters used in the template |
111
116
  |**[`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
117
  |**[`favicon`](#)**|`{String}`|``|Adds the given favicon path to the output HTML|
118
+ |**[`meta`](#)**|`{Object}`|`{}`|Allows to inject `meta`-tags. E.g. `meta: {viewport: 'width=device-width, initial-scale=1, shrink-to-fit=no'}`|
113
119
  |**[`minify`](#)**|`{Boolean\|Object}`|`true`|Pass [html-minifier](https://github.com/kangax/html-minifier#options-quick-reference)'s options as object to minify the output|
114
120
  |**[`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|
115
121
  |**[`cache`](#)**|`{Boolean}`|`true`|Emit the file only if it was changed|
116
122
  |**[`showErrors`](#)**|`{Boolean}`|`true`|Errors details will be written into the HTML page|
117
123
  |**[`chunks`](#)**|`{?}`|`?`|Allows you to add only some chunks (e.g only the unit-test chunk)|
118
124
  |**[`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
- |**[`excludeChunks`](#)**|`{String}`|``|Allows you to skip some chunks (e.g don't add the unit-test chunk)|
125
+ |**[`excludeChunks`](#)**|`{Array.<string>}`|``|Allows you to skip some chunks (e.g don't add the unit-test chunk)|
120
126
  |**[`xhtml`](#)**|`{Boolean}`|`false`|If `true` render the `link` tags as self-closing (XHTML compliant)|
121
127
 
122
128
  Here's an example webpack config illustrating how to use these options
@@ -143,7 +149,7 @@ Here's an example webpack config illustrating how to use these options
143
149
  To generate more than one HTML file, declare the plugin more than
144
150
  once in your plugins array
145
151
 
146
- **webpack.confg.js**
152
+ **webpack.config.js**
147
153
  ```js
148
154
  {
149
155
  entry: 'index.js',
@@ -330,15 +336,6 @@ plugins: [
330
336
 
331
337
  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
338
 
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
339
  <h2 align="center">Maintainers</h2>
343
340
 
344
341
  <table>
@@ -373,8 +370,46 @@ Before running the tests, make sure to execute `yarn link` and `yarn link html-w
373
370
  [tests]: http://img.shields.io/travis/jantimon/html-webpack-plugin.svg
374
371
  [tests-url]: https://travis-ci.org/jantimon/html-webpack-plugin
375
372
 
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
373
 
379
- [chat]: https://badges.gitter.im/webpack/webpack.svg
380
- [chat-url]: https://gitter.im/webpack/webpack
374
+ ## Contributors
375
+
376
+ This project exists thanks to all the people who contribute.
377
+
378
+ 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.
379
+
380
+ This project uses the [semistandard code style](https://github.com/Flet/semistandard).
381
+
382
+ <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>
383
+
384
+
385
+ ## Backers
386
+
387
+ Thank you to all our backers! 🙏 [Become a backer](https://opencollective.com/html-webpack-plugin#backer)
388
+
389
+ <a href="https://opencollective.com/html-webpack-plugin/backer/0/website?requireActive=false" target="_blank"><img src="https://opencollective.com/html-webpack-plugin/backer/0/avatar.svg?requireActive=false"></a>
390
+ <a href="https://opencollective.com/html-webpack-plugin/backer/1/website?requireActive=false" target="_blank"><img src="https://opencollective.com/html-webpack-plugin/backer/1/avatar.svg?requireActive=false"></a>
391
+ <a href="https://opencollective.com/html-webpack-plugin/backer/2/website?requireActive=false" target="_blank"><img src="https://opencollective.com/html-webpack-plugin/backer/2/avatar.svg?requireActive=false"></a>
392
+ <a href="https://opencollective.com/html-webpack-plugin/backer/3/website?requireActive=false" target="_blank"><img src="https://opencollective.com/html-webpack-plugin/backer/3/avatar.svg?requireActive=false"></a>
393
+ <a href="https://opencollective.com/html-webpack-plugin/backer/4/website?requireActive=false" target="_blank"><img src="https://opencollective.com/html-webpack-plugin/backer/4/avatar.svg?requireActive=false"></a>
394
+ <a href="https://opencollective.com/html-webpack-plugin/backer/5/website?requireActive=false" target="_blank"><img src="https://opencollective.com/html-webpack-plugin/backer/5/avatar.svg?requireActive=false"></a>
395
+ <a href="https://opencollective.com/html-webpack-plugin/backer/6/website?requireActive=false" target="_blank"><img src="https://opencollective.com/html-webpack-plugin/backer/6/avatar.svg?requireActive=false"></a>
396
+ <a href="https://opencollective.com/html-webpack-plugin/backer/7/website?requireActive=false" target="_blank"><img src="https://opencollective.com/html-webpack-plugin/backer/7/avatar.svg?requireActive=false"></a>
397
+ <a href="https://opencollective.com/html-webpack-plugin/backer/8/website?requireActive=false" target="_blank"><img src="https://opencollective.com/html-webpack-plugin/backer/8/avatar.svg?requireActive=false"></a>
398
+ <a href="https://opencollective.com/html-webpack-plugin/backer/9/website?requireActive=false" target="_blank"><img src="https://opencollective.com/html-webpack-plugin/backer/9/avatar.svg?requireActive=false"></a>
399
+
400
+ ## Sponsors
401
+
402
+ 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)
403
+
404
+ <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>
405
+ <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>
406
+ <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>
407
+ <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>
408
+ <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>
409
+ <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>
410
+ <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>
411
+ <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>
412
+ <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>
413
+ <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>
414
+
415
+
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,
@@ -29,6 +30,8 @@ class HtmlWebpackPlugin {
29
30
  showErrors: true,
30
31
  chunks: 'all',
31
32
  excludeChunks: [],
33
+ chunksSortMode: 'auto',
34
+ meta: {},
32
35
  title: 'Webpack App',
33
36
  xhtml: false
34
37
  }, options);
@@ -107,7 +110,7 @@ class HtmlWebpackPlugin {
107
110
  // Filter chunks (options.chunks and options.excludeCHunks)
108
111
  let chunks = self.filterChunks(allChunks, self.options.chunks, self.options.excludeChunks);
109
112
  // Sort chunks
110
- chunks = self.sortChunks(chunks, self.options.chunksSortMode, compilation.chunkGroups);
113
+ chunks = self.sortChunks(chunks, self.options.chunksSortMode, compilation);
111
114
  // Let plugins alter the chunks and the chunk sorting
112
115
  if (compilation.hooks) {
113
116
  chunks = compilation.hooks.htmlWebpackPluginAlterChunks.call(chunks, { plugin: self });
@@ -178,7 +181,7 @@ class HtmlWebpackPlugin {
178
181
  const html = result.html;
179
182
  const assets = result.assets;
180
183
  // Prepare script and link tags
181
- const assetTags = self.generateAssetTags(assets);
184
+ const assetTags = self.generateHtmlTags(assets);
182
185
  const pluginArgs = {head: assetTags.head, body: assetTags.body, plugin: self, chunks: chunks, outputName: self.childCompilationOutputName};
183
186
  // Allow plugins to change the assetTag definitions
184
187
  return applyPluginsAsyncWaterfall('html-webpack-plugin-alter-asset-tags', true, pluginArgs)
@@ -253,25 +256,29 @@ class HtmlWebpackPlugin {
253
256
  : Promise.reject('The loader "' + this.options.template + '" didn\'t return html.');
254
257
  }
255
258
 
259
+ /**
260
+ * Generate the template parameters for the template function
261
+ */
262
+ getTemplateParameters (compilation, assets) {
263
+ if (typeof this.options.templateParameters === 'function') {
264
+ return this.options.templateParameters(compilation, assets, this.options);
265
+ }
266
+ if (typeof this.options.templateParameters === 'object') {
267
+ return this.options.templateParameters;
268
+ }
269
+ return {};
270
+ }
271
+
256
272
  /**
257
273
  * Html post processing
258
274
  *
259
275
  * Returns a promise
260
276
  */
261
277
  executeTemplate (templateFunction, chunks, assets, compilation) {
262
- const self = this;
263
278
  return Promise.resolve()
264
279
  // Template processing
265
280
  .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
- };
281
+ const templateParams = this.getTemplateParameters(compilation, assets);
275
282
  let html = '';
276
283
  try {
277
284
  html = templateFunction(templateParams);
@@ -347,25 +354,14 @@ class HtmlWebpackPlugin {
347
354
  /**
348
355
  * Helper to sort chunks
349
356
  */
350
- sortChunks (chunks, sortMode, chunkGroups) {
351
- // Sort mode auto by default:
352
- if (typeof sortMode === 'undefined') {
353
- sortMode = 'auto';
354
- }
357
+ sortChunks (chunks, sortMode, compilation) {
355
358
  // Custom function
356
359
  if (typeof sortMode === 'function') {
357
360
  return chunks.sort(sortMode);
358
361
  }
359
- // Disabled sorting:
360
- if (sortMode === 'none') {
361
- return chunkSorter.none(chunks);
362
- }
363
- if (sortMode === 'manual') {
364
- return chunkSorter.manual(chunks, this.options.chunks);
365
- }
366
362
  // Check if the given sort mode is a valid chunkSorter sort mode
367
363
  if (typeof chunkSorter[sortMode] !== 'undefined') {
368
- return chunkSorter[sortMode](chunks, chunkGroups);
364
+ return chunkSorter[sortMode](chunks, this.options, compilation);
369
365
  }
370
366
  throw new Error('"' + sortMode + '" is not a valid chunk sort mode');
371
367
  }
@@ -477,15 +473,44 @@ class HtmlWebpackPlugin {
477
473
  return assets;
478
474
  }
479
475
 
476
+ /**
477
+ * Generate meta tags
478
+ */
479
+ getMetaTags () {
480
+ if (this.options.meta === false) {
481
+ return [];
482
+ }
483
+ // Make tags self-closing in case of xhtml
484
+ // Turn { "viewport" : "width=500, initial-scale=1" } into
485
+ // [{ name:"viewport" content:"width=500, initial-scale=1" }]
486
+ const selfClosingTag = !!this.options.xhtml;
487
+ const metaTagAttributeObjects = Object.keys(this.options.meta).map((metaName) => {
488
+ const metaTagContent = this.options.meta[metaName];
489
+ return (typeof metaTagContent === 'object') ? metaTagContent : {
490
+ name: metaName,
491
+ content: metaTagContent
492
+ };
493
+ });
494
+ // Turn [{ name:"viewport" content:"width=500, initial-scale=1" }] into
495
+ // the html-webpack-plugin tag structure
496
+ return metaTagAttributeObjects.map((metaTagAttributes) => {
497
+ return {
498
+ tagName: 'meta',
499
+ voidTag: true,
500
+ selfClosingTag: selfClosingTag,
501
+ attributes: metaTagAttributes
502
+ };
503
+ });
504
+ }
505
+
480
506
  /**
481
507
  * Injects the assets into the given html string
482
508
  */
483
- generateAssetTags (assets) {
509
+ generateHtmlTags (assets) {
484
510
  // Turn script files into script tags
485
511
  const scripts = assets.js.map(scriptPath => ({
486
512
  tagName: 'script',
487
513
  closeTag: true,
488
-
489
514
  attributes: {
490
515
  type: 'text/javascript',
491
516
  src: scriptPath
@@ -497,14 +522,14 @@ class HtmlWebpackPlugin {
497
522
  const styles = assets.css.map(stylePath => ({
498
523
  tagName: 'link',
499
524
  selfClosingTag: selfClosingTag,
500
-
525
+ voidTag: true,
501
526
  attributes: {
502
527
  href: stylePath,
503
528
  rel: 'stylesheet'
504
529
  }
505
530
  }));
506
531
  // Injection targets
507
- let head = [];
532
+ let head = this.getMetaTags();
508
533
  let body = [];
509
534
 
510
535
  // If there is a favicon present, add it to the head
@@ -512,6 +537,7 @@ class HtmlWebpackPlugin {
512
537
  head.push({
513
538
  tagName: 'link',
514
539
  selfClosingTag: selfClosingTag,
540
+ voidTag: true,
515
541
  attributes: {
516
542
  rel: 'shortcut icon',
517
543
  href: assets.favicon
@@ -536,8 +562,8 @@ class HtmlWebpackPlugin {
536
562
  const htmlRegExp = /(<html[^>]*>)/i;
537
563
  const headRegExp = /(<\/head\s*>)/i;
538
564
  const bodyRegExp = /(<\/body\s*>)/i;
539
- const body = assetTags.body.map(this.createHtmlTag);
540
- const head = assetTags.head.map(this.createHtmlTag);
565
+ const body = assetTags.body.map(this.createHtmlTag.bind(this));
566
+ const head = assetTags.head.map(this.createHtmlTag.bind(this));
541
567
 
542
568
  if (body.length) {
543
569
  if (bodyRegExp.test(html)) {
@@ -684,4 +710,20 @@ function trainCaseToCamelCase (word) {
684
710
  return word.replace(/-([\w])/g, (match, p1) => p1.toUpperCase());
685
711
  }
686
712
 
713
+ /**
714
+ * The default for options.templateParameter
715
+ * Generate the template parameters
716
+ */
717
+ function templateParametersGenerator (compilation, assets, options) {
718
+ return {
719
+ compilation: compilation,
720
+ webpack: compilation.getStats().toJson(),
721
+ webpackConfig: compilation.options,
722
+ htmlWebpackPlugin: {
723
+ files: assets,
724
+ options: options
725
+ }
726
+ };
727
+ }
728
+
687
729
  module.exports = HtmlWebpackPlugin;
@@ -26,7 +26,8 @@ const _ = require('lodash');
26
26
 
27
27
  @return {Array} A topologically sorted version of the input chunks
28
28
  */
29
- module.exports.dependency = (chunks, chunkGroups) => {
29
+ module.exports.dependency = (chunks, options, compilation) => {
30
+ const chunkGroups = compilation.chunkGroups;
30
31
  if (!chunks) {
31
32
  return chunks;
32
33
  }
@@ -107,7 +108,8 @@ module.exports.none = chunks => chunks;
107
108
  * @param {Array} chunks the chunks to sort
108
109
  * @return {Array} The sorted chunks
109
110
  */
110
- module.exports.manual = (chunks, specifyChunks) => {
111
+ module.exports.manual = (chunks, options) => {
112
+ const specifyChunks = options.chunks;
111
113
  const chunksResult = [];
112
114
  let filterResult = [];
113
115
  if (Array.isArray(specifyChunks)) {
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,7 +36,7 @@ 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 = _.assign({}, compilation.assets[outputOptions.filename]);
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
@@ -47,7 +46,14 @@ module.exports.compileTemplate = function compileTemplate (template, context, ou
47
46
  new NodeTemplatePlugin(outputOptions).apply(childCompiler);
48
47
  new NodeTargetPlugin().apply(childCompiler);
49
48
  new LibraryTemplatePlugin('HTML_WEBPACK_PLUGIN_RESULT', 'var').apply(childCompiler);
50
- new SingleEntryPlugin(this.context, template).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
+
51
57
  new LoaderTargetPlugin('node').apply(childCompiler);
52
58
 
53
59
  // Fix for "Uncaught TypeError: __webpack_require__(...) is not a function"
package/lib/loader.js CHANGED
@@ -25,27 +25,11 @@ module.exports = function (source) {
25
25
  //
26
26
  // Get templating options
27
27
  const options = this.query !== '' ? loaderUtils.parseQuery(this.query) : {};
28
- // Webpack 2 does not allow with() statements, which lodash templates use to unwrap
29
- // the parameters passed to the compiled template inside the scope. We therefore
30
- // need to unwrap them ourselves here. This is essentially what lodash does internally
31
- // To tell lodash it should not use with we set a variable
32
28
  const template = _.template(source, _.defaults(options, { variable: 'data' }));
33
- // All templateVariables which should be available
34
- // @see HtmlWebpackPlugin.prototype.executeTemplate
35
- const templateVariables = [
36
- 'compilation',
37
- 'webpack',
38
- 'webpackConfig',
39
- 'htmlWebpackPlugin'
40
- ];
41
- return 'var _ = require(' + loaderUtils.stringifyRequest(this, require.resolve('lodash')) + ');' +
42
- 'module.exports = function (templateParams) {' +
43
- // Declare the template variables in the outer scope of the
44
- // lodash template to unwrap them
45
- templateVariables.map(function (variableName) {
46
- return 'var ' + variableName + ' = templateParams.' + variableName;
47
- }).join(';') + ';' +
29
+ // Require !!lodash - using !! will disable all loaders (e.g. babel)
30
+ return 'var _ = require(' + loaderUtils.stringifyRequest(this, '!!' + require.resolve('lodash')) + ');' +
31
+ 'module.exports = function (templateParams) { with(templateParams) {' +
48
32
  // Execute the lodash template
49
33
  'return (' + template.source + ')();' +
50
- '}';
34
+ '}}';
51
35
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "html-webpack-plugin",
3
- "version": "3.0.6",
3
+ "version": "3.2.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)",
@@ -12,6 +12,7 @@
12
12
  ],
13
13
  "scripts": {
14
14
  "pretest": "semistandard",
15
+ "commit": "git-cz",
15
16
  "build-examples": "node examples/build-examples.js",
16
17
  "test": "jasmine",
17
18
  "release": "standard-version"
@@ -23,7 +24,9 @@
23
24
  },
24
25
  "devDependencies": {
25
26
  "appcache-webpack-plugin": "^1.3.0",
27
+ "commitizen": "2.9.6",
26
28
  "css-loader": "^0.26.1",
29
+ "cz-conventional-changelog": "2.1.0",
27
30
  "dir-compare": "1.3.0",
28
31
  "es6-promise": "^4.0.5",
29
32
  "extract-text-webpack-plugin": "^1.0.1",
@@ -64,6 +67,11 @@
64
67
  "homepage": "https://github.com/jantimon/html-webpack-plugin",
65
68
  "repository": "https://github.com/jantimon/html-webpack-plugin.git",
66
69
  "engines": {
67
- "node": ">=6.11.5"
70
+ "node": ">=6.9"
71
+ },
72
+ "config": {
73
+ "commitizen": {
74
+ "path": "./node_modules/cz-conventional-changelog"
75
+ }
68
76
  }
69
77
  }