html-webpack-plugin 2.27.1 → 2.30.1

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
@@ -1,6 +1,23 @@
1
1
  Change History
2
2
  ==============
3
3
 
4
+ v2.30.1
5
+ ---
6
+ * Revert part the performance optimization (#723) because of #753.
7
+
8
+ v2.30.0
9
+ ---
10
+ * Add manual sort
11
+ * Performance improvements (#723)
12
+
13
+ v2.29.0
14
+ ---
15
+ * Add support for Webpack 3
16
+
17
+ v2.28.0
18
+ ---
19
+ * Backport 3.x void tag for plugin authors
20
+
4
21
  v2.27.1
5
22
  ---
6
23
  * Revert 2.25.0 loader resolving
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  HTML Webpack Plugin
2
2
  ===================
3
- [![npm version](https://badge.fury.io/js/html-webpack-plugin.svg)](http://badge.fury.io/js/html-webpack-plugin) [![Dependency Status](https://david-dm.org/ampedandwired/html-webpack-plugin.svg)](https://david-dm.org/ampedandwired/html-webpack-plugin) [![Build status](https://travis-ci.org/ampedandwired/html-webpack-plugin.svg)](https://travis-ci.org/ampedandwired/html-webpack-plugin) [![Windows build status](https://ci.appveyor.com/api/projects/status/github/ampedandwired/html-webpack-plugin?svg=true&branch=master)](https://ci.appveyor.com/project/jantimon/html-webpack-plugin) [![js-semistandard-style](https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg?style=flat-square)](https://github.com/Flet/semistandard) [![bitHound Dependencies](https://www.bithound.io/github/ampedandwired/html-webpack-plugin/badges/dependencies.svg)](https://www.bithound.io/github/ampedandwired/html-webpack-plugin/master/dependencies/npm) [![license](https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000)]()
3
+ [![npm version](https://badge.fury.io/js/html-webpack-plugin.svg)](http://badge.fury.io/js/html-webpack-plugin) [![Dependency Status](https://david-dm.org/jantimon/html-webpack-plugin.svg)](https://david-dm.org/jantimon/html-webpack-plugin) [![Build status](https://travis-ci.org/jantimon/html-webpack-plugin.svg)](https://travis-ci.org/jantimon/html-webpack-plugin) [![Windows build status](https://ci.appveyor.com/api/projects/status/github/jantimon/html-webpack-plugin?svg=true&branch=master)](https://ci.appveyor.com/project/jantimon/html-webpack-plugin) [![js-semistandard-style](https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg?style=flat-square)](https://github.com/Flet/semistandard) [![bitHound Dependencies](https://www.bithound.io/github/jantimon/html-webpack-plugin/badges/dependencies.svg)](https://www.bithound.io/github/jantimon/html-webpack-plugin/master/dependencies/npm) [![license](https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000)]()
4
4
 
5
5
  [![NPM](https://nodei.co/npm/html-webpack-plugin.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/html-webpack-plugin/)
6
6
 
@@ -9,7 +9,7 @@ webpack bundles. This is especially useful for webpack bundles that include
9
9
  a hash in the filename which changes every compilation. You can either let the plugin generate an HTML file for you, supply
10
10
  your own template using lodash templates or use your own loader.
11
11
 
12
- Maintainer: Jan Nicklas [@jantimon](https://twitter.com/jantimon)
12
+ Maintainer: Jan Nicklas [@jantimon](https://twitter.com/jantimon) and Thomas Sileghem [@mastilver](https://twitter.com/mastilver)
13
13
 
14
14
  Installation
15
15
  ------------
@@ -21,20 +21,23 @@ $ npm install html-webpack-plugin --save-dev
21
21
  Third party addons:
22
22
  -------------
23
23
 
24
- The html-webpack-plugin provides [hooks](https://github.com/ampedandwired/html-webpack-plugin#events) to extend it to your needs.
24
+ The html-webpack-plugin provides [hooks](https://github.com/jantimon/html-webpack-plugin#events) to extend it to your needs.
25
25
  There are already some really powerful plugins which can be integrated with zero configuration:
26
26
 
27
27
  * [webpack-subresource-integrity](https://www.npmjs.com/package/webpack-subresource-integrity) for enhanced asset security
28
28
  * [appcache-webpack-plugin](https://github.com/lettertwo/appcache-webpack-plugin) for iOS and Android offline usage
29
29
  * [favicons-webpack-plugin](https://github.com/jantimon/favicons-webpack-plugin) which generates favicons and icons for iOS, Android and desktop browsers
30
- * [html-webpack-harddisk-plugin](https://github.com/jantimon/html-webpack-harddisk-plugin)
30
+ * [html-webpack-harddisk-plugin](https://github.com/jantimon/html-webpack-harddisk-plugin) can be used to always write to disk the html file, useful when webpack-dev-server / HMR are being used
31
31
  * [html-webpack-inline-source-plugin](https://github.com/DustinJackson/html-webpack-inline-source-plugin) to inline your assets in the resulting HTML file
32
- * [html-webpack-exclude-assets-plugin](https://github.com/jamesjieye/html-webpack-exclude-assets-plugin) for excluding assets using regular expressions
32
+ * [html-webpack-exclude-assets-plugin](https://github.com/jamesjieye/html-webpack-exclude-assets-plugin) for excluding assets using regular expressions
33
33
  * [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).
34
34
  * [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 in-line them
35
35
  * [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
36
- * [resource-hints-webpack-plugin](https://github.com/jantimon/resource-hints-webpack-plugin) to add resource hints for faster initial page loads
37
-
36
+ * [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'>`
37
+ * [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
38
+ * [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
39
+ * [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>`.
40
+
38
41
  Basic Usage
39
42
  -----------
40
43
 
@@ -47,7 +50,7 @@ var HtmlWebpackPlugin = require('html-webpack-plugin');
47
50
  var webpackConfig = {
48
51
  entry: 'index.js',
49
52
  output: {
50
- path: 'dist',
53
+ path: __dirname + '/dist',
51
54
  filename: 'index_bundle.js'
52
55
  },
53
56
  plugins: [new HtmlWebpackPlugin()]
@@ -83,16 +86,16 @@ Allowed values are as follows:
83
86
  - `title`: The title to use for the generated HTML document.
84
87
  - `filename`: The file to write the HTML to. Defaults to `index.html`.
85
88
  You can specify a subdirectory here too (eg: `assets/admin.html`).
86
- - `template`: Webpack require path to the template. Please see the [docs](https://github.com/ampedandwired/html-webpack-plugin/blob/master/docs/template-option.md) for details.
89
+ - `template`: 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.
87
90
  - `inject`: `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.
88
91
  - `favicon`: Adds the given favicon path to the output html.
89
- - `minify`: `{...} | false` Pass a [html-minifier](https://github.com/kangax/html-minifier#options-quick-reference) options object to minify the output.
92
+ - `minify`: `{...} | false` Pass [html-minifier](https://github.com/kangax/html-minifier#options-quick-reference)'s options as object to minify the output.
90
93
  - `hash`: `true | false` if `true` then append a unique webpack compilation hash to all
91
94
  included scripts and CSS files. This is useful for cache busting.
92
95
  - `cache`: `true | false` if `true` (default) try to emit the file only if it was changed.
93
96
  - `showErrors`: `true | false` if `true` (default) errors details will be written into the HTML page.
94
97
  - `chunks`: Allows you to add only some chunks (e.g. only the unit-test chunk)
95
- - `chunksSortMode`: Allows to control how chunks should be sorted before they are included to the html. Allowed values: 'none' | 'auto' | 'dependency' | {function} - default: 'auto'
98
+ - `chunksSortMode`: Allows to control how chunks should be sorted before they are included to the html. Allowed values: 'none' | 'auto' | 'dependency' |'manual' | {function} - default: 'auto'
96
99
  - `excludeChunks`: Allows you to skip some chunks (e.g. don't add the unit-test chunk)
97
100
  - `xhtml`: `true | false` If `true` render the `link` tags as self-closing, XHTML compliant. Default is `false`
98
101
 
@@ -101,7 +104,7 @@ Here's an example webpack config illustrating how to use these options:
101
104
  {
102
105
  entry: 'index.js',
103
106
  output: {
104
- path: 'dist',
107
+ path: __dirname + '/dist',
105
108
  filename: 'index_bundle.js'
106
109
  },
107
110
  plugins: [
@@ -116,9 +119,9 @@ Here's an example webpack config illustrating how to use these options:
116
119
  FAQ
117
120
  ----
118
121
 
119
- * [Why is my HTML minified?](https://github.com/ampedandwired/html-webpack-plugin/blob/master/docs/template-option.md)
120
- * [Why is my `<% ... %>` template not working?](https://github.com/ampedandwired/html-webpack-plugin/blob/master/docs/template-option.md)
121
- * [How can I use handlebars/pug/ejs as template engine](https://github.com/ampedandwired/html-webpack-plugin/blob/master/docs/template-option.md)
122
+ * [Why is my HTML minified?](https://github.com/jantimon/html-webpack-plugin/blob/master/docs/template-option.md)
123
+ * [Why is my `<% ... %>` template not working?](https://github.com/jantimon/html-webpack-plugin/blob/master/docs/template-option.md)
124
+ * [How can I use handlebars/pug/ejs as template engine](https://github.com/jantimon/html-webpack-plugin/blob/master/docs/template-option.md)
122
125
 
123
126
  Generating Multiple HTML Files
124
127
  ------------------------------
@@ -128,7 +131,7 @@ once in your plugins array:
128
131
  {
129
132
  entry: 'index.js',
130
133
  output: {
131
- path: 'dist',
134
+ path: __dirname + '/dist',
132
135
  filename: 'index_bundle.js'
133
136
  },
134
137
  plugins: [
@@ -224,7 +227,7 @@ The following variables are available in the template:
224
227
  - `webpack`: the webpack [stats](https://github.com/webpack/docs/wiki/node.js-api#stats)
225
228
  object. Note that this is the stats object as it was at the time the HTML template
226
229
  was emitted and as such may not have the full set of stats that are available
227
- after the wepback run is complete.
230
+ after the webpack run is complete.
228
231
 
229
232
  - `webpackConfig`: the webpack configuration that was used for this compilation. This
230
233
  can be used, for example, to get the `publicPath` (`webpackConfig.output.publicPath`).
@@ -309,11 +312,11 @@ Note that the callback must be passed the htmlPluginData in order to pass this o
309
312
 
310
313
  # Contribution
311
314
 
312
- You're free to contribute to this project by submitting [issues](https://github.com/ampedandwired/html-webpack-plugin/issues) and/or [pull requests](https://github.com/ampedandwired/html-webpack-plugin/pulls). This project is test-driven, so keep in mind that every change and new feature should be covered by tests.
315
+ 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.
313
316
  This project uses the [semistandard code style](https://github.com/Flet/semistandard).
314
317
 
315
318
  Before running the tests, make sure to execute `yarn link` and `yarn link html-webpack-plugin` (or the npm variant of this).
316
319
 
317
320
  # License
318
321
 
319
- This project is licensed under [MIT](https://github.com/ampedandwired/html-webpack-plugin/blob/master/LICENSE).
322
+ This project is licensed under [MIT](https://github.com/jantimon/html-webpack-plugin/blob/master/LICENSE).
package/index.js CHANGED
@@ -144,7 +144,6 @@ HtmlWebpackPlugin.prototype.apply = function (compiler) {
144
144
  .then(function (result) {
145
145
  var html = result.html;
146
146
  var assets = result.assets;
147
- var chunks = result.chunks;
148
147
  // Prepare script and link tags
149
148
  var assetTags = self.generateAssetTags(assets);
150
149
  var pluginArgs = {head: assetTags.head, body: assetTags.body, plugin: self, chunks: chunks, outputName: self.childCompilationOutputName};
@@ -345,7 +344,7 @@ HtmlWebpackPlugin.prototype.sortChunks = function (chunks, sortMode) {
345
344
  }
346
345
  // Check if the given sort mode is a valid chunkSorter sort mode
347
346
  if (typeof chunkSorter[sortMode] !== 'undefined') {
348
- return chunkSorter[sortMode](chunks);
347
+ return chunkSorter[sortMode](chunks, this.options.chunks);
349
348
  }
350
349
  throw new Error('"' + sortMode + '" is not a valid chunk sort mode');
351
350
  };
@@ -361,7 +360,11 @@ HtmlWebpackPlugin.prototype.filterChunks = function (chunks, includedChunks, exc
361
360
  return false;
362
361
  }
363
362
  // Skip if the chunk should be lazy loaded
364
- if (!chunk.initial) {
363
+ if (typeof chunk.isInitial === 'function') {
364
+ if (!chunk.isInitial()) {
365
+ return false;
366
+ }
367
+ } else if (!chunk.initial) {
365
368
  return false;
366
369
  }
367
370
  // Skip if the chunks should be filtered and the given chunk was not added explicity
@@ -385,12 +388,12 @@ HtmlWebpackPlugin.prototype.isHotUpdateCompilation = function (assets) {
385
388
 
386
389
  HtmlWebpackPlugin.prototype.htmlWebpackPluginAssets = function (compilation, chunks) {
387
390
  var self = this;
388
- var webpackStatsJson = compilation.getStats().toJson();
391
+ var compilationHash = compilation.hash;
389
392
 
390
393
  // Use the configured public path or build a relative path
391
394
  var publicPath = typeof compilation.options.output.publicPath !== 'undefined'
392
395
  // If a hard coded public path exists use it
393
- ? compilation.mainTemplate.getPublicPath({hash: webpackStatsJson.hash})
396
+ ? compilation.mainTemplate.getPublicPath({hash: compilationHash})
394
397
  // If no public path was set get a relative url path
395
398
  : path.relative(path.resolve(compilation.options.output.path, path.dirname(self.childCompilationOutputName)), compilation.options.output.path)
396
399
  .split(path.sep).join('/');
@@ -416,8 +419,8 @@ HtmlWebpackPlugin.prototype.htmlWebpackPluginAssets = function (compilation, chu
416
419
 
417
420
  // Append a hash for cache busting
418
421
  if (this.options.hash) {
419
- assets.manifest = self.appendHash(assets.manifest, webpackStatsJson.hash);
420
- assets.favicon = self.appendHash(assets.favicon, webpackStatsJson.hash);
422
+ assets.manifest = self.appendHash(assets.manifest, compilationHash);
423
+ assets.favicon = self.appendHash(assets.favicon, compilationHash);
421
424
  }
422
425
 
423
426
  for (var i = 0; i < chunks.length; i++) {
@@ -434,7 +437,7 @@ HtmlWebpackPlugin.prototype.htmlWebpackPluginAssets = function (compilation, chu
434
437
  // Append a hash for cache busting
435
438
  if (this.options.hash) {
436
439
  chunkFiles = chunkFiles.map(function (chunkFile) {
437
- return self.appendHash(chunkFile, webpackStatsJson.hash);
440
+ return self.appendHash(chunkFile, compilationHash);
438
441
  });
439
442
  }
440
443
 
@@ -522,8 +525,8 @@ HtmlWebpackPlugin.prototype.generateAssetTags = function (assets) {
522
525
  */
523
526
  HtmlWebpackPlugin.prototype.injectAssetsIntoHtml = function (html, assets, assetTags) {
524
527
  var htmlRegExp = /(<html[^>]*>)/i;
525
- var headRegExp = /(<\/head>)/i;
526
- var bodyRegExp = /(<\/body>)/i;
528
+ var headRegExp = /(<\/head\s*>)/i;
529
+ var bodyRegExp = /(<\/body\s*>)/i;
527
530
  var body = assetTags.body.map(this.createHtmlTag);
528
531
  var head = assetTags.head.map(this.createHtmlTag);
529
532
 
@@ -80,6 +80,28 @@ module.exports.none = function (chunks) {
80
80
  return chunks;
81
81
  };
82
82
 
83
+ /**
84
+ * Sort manually by the chunks
85
+ * @param {Array} chunks the chunks to sort
86
+ * @return {Array} The sorted chunks
87
+ */
88
+ module.exports.manual = function (chunks, specifyChunks) {
89
+ var chunksResult = [];
90
+ var filterResult = [];
91
+ if (Array.isArray(specifyChunks)) {
92
+ for (var i = 0; i < specifyChunks.length; i++) {
93
+ filterResult = chunks.filter(function (chunk) {
94
+ if (chunk.names[0] && chunk.names[0] === specifyChunks[i]) {
95
+ return true;
96
+ }
97
+ return false;
98
+ });
99
+ filterResult.length > 0 && chunksResult.push(filterResult[0]);
100
+ }
101
+ }
102
+ return chunksResult;
103
+ };
104
+
83
105
  /**
84
106
  * Defines the default sorter.
85
107
  */
@@ -88,6 +110,6 @@ module.exports.auto = module.exports.id;
88
110
  // In webpack 2 the ids have been flipped.
89
111
  // Therefore the id sort doesn't work the same way as it did for webpack 1
90
112
  // Luckily the dependency sort is working as expected
91
- if (require('webpack/package.json').version.split('.')[0] === '2') {
113
+ if (Number(require('webpack/package.json').version.split('.')[0]) > 1) {
92
114
  module.exports.auto = module.exports.dependency;
93
115
  }
package/lib/loader.js CHANGED
@@ -17,7 +17,7 @@ module.exports = function (source) {
17
17
  return source;
18
18
  }
19
19
  // Skip .js files
20
- if (/\.js$/.test(this.request)) {
20
+ if (/\.js$/.test(this.resourcePath)) {
21
21
  return source;
22
22
  }
23
23
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "html-webpack-plugin",
3
- "version": "2.27.1",
3
+ "version": "2.30.1",
4
4
  "description": "Simplifies creation of HTML files to serve your webpack bundles",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -16,7 +16,7 @@
16
16
  },
17
17
  "repository": {
18
18
  "type": "git",
19
- "url": "https://github.com/ampedandwired/html-webpack-plugin.git"
19
+ "url": "https://github.com/jantimon/html-webpack-plugin.git"
20
20
  },
21
21
  "keywords": [
22
22
  "webpack",
@@ -27,9 +27,9 @@
27
27
  "author": "Charles Blaxland <charles.blaxland@gmail.com> (https://github.com/ampedandwired)",
28
28
  "license": "MIT",
29
29
  "bugs": {
30
- "url": "https://github.com/ampedandwired/html-webpack-plugin/issues"
30
+ "url": "https://github.com/jantimon/html-webpack-plugin/issues"
31
31
  },
32
- "homepage": "https://github.com/ampedandwired/html-webpack-plugin",
32
+ "homepage": "https://github.com/jantimon/html-webpack-plugin",
33
33
  "semistandard": {
34
34
  "ignore": [
35
35
  "examples/*/dist/**/*.*"
@@ -63,6 +63,6 @@
63
63
  "toposort": "^1.0.0"
64
64
  },
65
65
  "peerDependencies": {
66
- "webpack": "1 || ^2 || ^2.1.0-beta || ^2.2.0-rc"
66
+ "webpack": "1 || ^2 || ^2.1.0-beta || ^2.2.0-rc || ^3"
67
67
  }
68
68
  }