html-webpack-plugin 2.26.0 → 2.29.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 +13 -0
- package/README.md +24 -15
- package/index.js +10 -5
- package/lib/chunksorter.js +4 -2
- package/lib/loader.js +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
Change History
|
|
2
2
|
==============
|
|
3
3
|
|
|
4
|
+
v2.28.0
|
|
5
|
+
---
|
|
6
|
+
* Backport 3.x void tag for plugin authors
|
|
7
|
+
|
|
8
|
+
v2.27.1
|
|
9
|
+
---
|
|
10
|
+
* Revert 2.25.0 loader resolving
|
|
11
|
+
|
|
12
|
+
v2.27.0
|
|
13
|
+
---
|
|
14
|
+
* Fix a chunksorter webpack 2 issue (#569)
|
|
15
|
+
* Fix template path resolving(#542)
|
|
16
|
+
|
|
4
17
|
v2.26.0
|
|
5
18
|
---
|
|
6
19
|
* Allow plugins to add attributes without values to the `<script>` and `<link>` tags
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
HTML Webpack Plugin
|
|
2
2
|
===================
|
|
3
|
-
[](http://badge.fury.io/js/html-webpack-plugin) [](http://badge.fury.io/js/html-webpack-plugin) [](https://david-dm.org/jantimon/html-webpack-plugin) [](https://travis-ci.org/jantimon/html-webpack-plugin) [](https://ci.appveyor.com/project/jantimon/html-webpack-plugin) [](https://github.com/Flet/semistandard) [](https://www.bithound.io/github/jantimon/html-webpack-plugin/master/dependencies/npm) []()
|
|
4
4
|
|
|
5
5
|
[](https://nodei.co/npm/html-webpack-plugin/)
|
|
6
6
|
|
|
@@ -21,16 +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/
|
|
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
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
|
+
* [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
|
+
* [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 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
|
+
|
|
34
41
|
Basic Usage
|
|
35
42
|
-----------
|
|
36
43
|
|
|
@@ -43,7 +50,7 @@ var HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
|
43
50
|
var webpackConfig = {
|
|
44
51
|
entry: 'index.js',
|
|
45
52
|
output: {
|
|
46
|
-
path: 'dist',
|
|
53
|
+
path: __dirname + '/dist',
|
|
47
54
|
filename: 'index_bundle.js'
|
|
48
55
|
},
|
|
49
56
|
plugins: [new HtmlWebpackPlugin()]
|
|
@@ -79,10 +86,10 @@ Allowed values are as follows:
|
|
|
79
86
|
- `title`: The title to use for the generated HTML document.
|
|
80
87
|
- `filename`: The file to write the HTML to. Defaults to `index.html`.
|
|
81
88
|
You can specify a subdirectory here too (eg: `assets/admin.html`).
|
|
82
|
-
- `template`: Webpack require path to the template. Please see the [docs](https://github.com/
|
|
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.
|
|
83
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.
|
|
84
91
|
- `favicon`: Adds the given favicon path to the output html.
|
|
85
|
-
- `minify`: `{...} | false` Pass
|
|
92
|
+
- `minify`: `{...} | false` Pass [html-minifier](https://github.com/kangax/html-minifier#options-quick-reference)'s options as object to minify the output.
|
|
86
93
|
- `hash`: `true | false` if `true` then append a unique webpack compilation hash to all
|
|
87
94
|
included scripts and CSS files. This is useful for cache busting.
|
|
88
95
|
- `cache`: `true | false` if `true` (default) try to emit the file only if it was changed.
|
|
@@ -97,7 +104,7 @@ Here's an example webpack config illustrating how to use these options:
|
|
|
97
104
|
{
|
|
98
105
|
entry: 'index.js',
|
|
99
106
|
output: {
|
|
100
|
-
path: 'dist',
|
|
107
|
+
path: __dirname + '/dist',
|
|
101
108
|
filename: 'index_bundle.js'
|
|
102
109
|
},
|
|
103
110
|
plugins: [
|
|
@@ -112,9 +119,9 @@ Here's an example webpack config illustrating how to use these options:
|
|
|
112
119
|
FAQ
|
|
113
120
|
----
|
|
114
121
|
|
|
115
|
-
* [Why is my HTML minified?](https://github.com/
|
|
116
|
-
* [Why is my `<% ... %>` template not working?](https://github.com/
|
|
117
|
-
* [How can I use handlebars/pug/ejs as template engine](https://github.com/
|
|
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)
|
|
118
125
|
|
|
119
126
|
Generating Multiple HTML Files
|
|
120
127
|
------------------------------
|
|
@@ -124,7 +131,7 @@ once in your plugins array:
|
|
|
124
131
|
{
|
|
125
132
|
entry: 'index.js',
|
|
126
133
|
output: {
|
|
127
|
-
path: 'dist',
|
|
134
|
+
path: __dirname + '/dist',
|
|
128
135
|
filename: 'index_bundle.js'
|
|
129
136
|
},
|
|
130
137
|
plugins: [
|
|
@@ -220,7 +227,7 @@ The following variables are available in the template:
|
|
|
220
227
|
- `webpack`: the webpack [stats](https://github.com/webpack/docs/wiki/node.js-api#stats)
|
|
221
228
|
object. Note that this is the stats object as it was at the time the HTML template
|
|
222
229
|
was emitted and as such may not have the full set of stats that are available
|
|
223
|
-
after the
|
|
230
|
+
after the webpack run is complete.
|
|
224
231
|
|
|
225
232
|
- `webpackConfig`: the webpack configuration that was used for this compilation. This
|
|
226
233
|
can be used, for example, to get the `publicPath` (`webpackConfig.output.publicPath`).
|
|
@@ -305,9 +312,11 @@ Note that the callback must be passed the htmlPluginData in order to pass this o
|
|
|
305
312
|
|
|
306
313
|
# Contribution
|
|
307
314
|
|
|
308
|
-
You're free to contribute to this project by submitting [issues](https://github.com/
|
|
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.
|
|
309
316
|
This project uses the [semistandard code style](https://github.com/Flet/semistandard).
|
|
310
317
|
|
|
318
|
+
Before running the tests, make sure to execute `yarn link` and `yarn link html-webpack-plugin` (or the npm variant of this).
|
|
319
|
+
|
|
311
320
|
# License
|
|
312
321
|
|
|
313
|
-
This project is licensed under [MIT](https://github.com/
|
|
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};
|
|
@@ -233,6 +232,9 @@ HtmlWebpackPlugin.prototype.evaluateCompilationResult = function (compilation, s
|
|
|
233
232
|
} catch (e) {
|
|
234
233
|
return Promise.reject(e);
|
|
235
234
|
}
|
|
235
|
+
if (typeof newSource === 'object' && newSource.__esModule && newSource.default) {
|
|
236
|
+
newSource = newSource.default;
|
|
237
|
+
}
|
|
236
238
|
return typeof newSource === 'string' || typeof newSource === 'function'
|
|
237
239
|
? Promise.resolve(newSource)
|
|
238
240
|
: Promise.reject('The loader "' + this.options.template + '" didn\'t return html.');
|
|
@@ -591,9 +593,12 @@ HtmlWebpackPlugin.prototype.createHtmlTag = function (tagDefinition) {
|
|
|
591
593
|
}
|
|
592
594
|
return attributeName + '="' + tagDefinition.attributes[attributeName] + '"';
|
|
593
595
|
});
|
|
594
|
-
|
|
596
|
+
// Backport of 3.x void tag definition
|
|
597
|
+
var voidTag = tagDefinition.voidTag !== undefined ? tagDefinition.voidTag : !tagDefinition.closeTag;
|
|
598
|
+
var selfClosingTag = tagDefinition.voidTag !== undefined ? tagDefinition.voidTag && this.options.xhtml : tagDefinition.selfClosingTag;
|
|
599
|
+
return '<' + [tagDefinition.tagName].concat(attributes).join(' ') + (selfClosingTag ? '/' : '') + '>' +
|
|
595
600
|
(tagDefinition.innerHTML || '') +
|
|
596
|
-
(
|
|
601
|
+
(voidTag ? '' : '</' + tagDefinition.tagName + '>');
|
|
597
602
|
};
|
|
598
603
|
|
|
599
604
|
/**
|
|
@@ -602,11 +607,11 @@ HtmlWebpackPlugin.prototype.createHtmlTag = function (tagDefinition) {
|
|
|
602
607
|
HtmlWebpackPlugin.prototype.getFullTemplatePath = function (template, context) {
|
|
603
608
|
// If the template doesn't use a loader use the lodash template loader
|
|
604
609
|
if (template.indexOf('!') === -1) {
|
|
605
|
-
template = '
|
|
610
|
+
template = require.resolve('./lib/loader.js') + '!' + path.resolve(context, template);
|
|
606
611
|
}
|
|
607
612
|
// Resolve template path
|
|
608
613
|
return template.replace(
|
|
609
|
-
/([!])([^/\\][^!?]+|[^/\\!?])(
|
|
614
|
+
/([!])([^/\\][^!?]+|[^/\\!?])($|\?[^!?\n]+$)/,
|
|
610
615
|
function (match, prefix, filepath, postfix) {
|
|
611
616
|
return prefix + path.resolve(filepath) + postfix;
|
|
612
617
|
});
|
package/lib/chunksorter.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var toposort = require('toposort');
|
|
4
|
+
var _ = require('lodash');
|
|
4
5
|
|
|
5
6
|
/*
|
|
6
7
|
Sorts dependencies between chunks by their "parents" attribute.
|
|
@@ -40,7 +41,8 @@ module.exports.dependency = function (chunks) {
|
|
|
40
41
|
if (chunk.parents) {
|
|
41
42
|
// Add an edge for each parent (parent -> child)
|
|
42
43
|
chunk.parents.forEach(function (parentId) {
|
|
43
|
-
|
|
44
|
+
// webpack2 chunk.parents are chunks instead of string id(s)
|
|
45
|
+
var parentChunk = _.isObject(parentId) ? parentId : nodeMap[parentId];
|
|
44
46
|
// If the parent chunk does not exist (e.g. because of an excluded chunk)
|
|
45
47
|
// we ignore that parent
|
|
46
48
|
if (parentChunk) {
|
|
@@ -86,6 +88,6 @@ module.exports.auto = module.exports.id;
|
|
|
86
88
|
// In webpack 2 the ids have been flipped.
|
|
87
89
|
// Therefore the id sort doesn't work the same way as it did for webpack 1
|
|
88
90
|
// Luckily the dependency sort is working as expected
|
|
89
|
-
if (require('webpack/package.json').version.split('.')[0]
|
|
91
|
+
if (Number(require('webpack/package.json').version.split('.')[0]) > 1) {
|
|
90
92
|
module.exports.auto = module.exports.dependency;
|
|
91
93
|
}
|
package/lib/loader.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "html-webpack-plugin",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.29.0",
|
|
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/
|
|
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/
|
|
30
|
+
"url": "https://github.com/jantimon/html-webpack-plugin/issues"
|
|
31
31
|
},
|
|
32
|
-
"homepage": "https://github.com/
|
|
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
|
}
|