html-webpack-plugin 2.21.0 → 2.24.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 +19 -0
- package/README.md +25 -10
- package/index.js +37 -15
- package/lib/compiler.js +12 -12
- package/package.json +24 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
Change History
|
|
2
2
|
==============
|
|
3
3
|
|
|
4
|
+
v2.24.0
|
|
5
|
+
---
|
|
6
|
+
* Update dependencies
|
|
7
|
+
* Add deprecate warning for plugins not returning a result
|
|
8
|
+
* Add [path] for favicons
|
|
9
|
+
|
|
10
|
+
v2.23.0
|
|
11
|
+
---
|
|
12
|
+
* Update dependencies
|
|
13
|
+
* Stop automated tests for webpack 2 beta because of #401
|
|
14
|
+
|
|
15
|
+
v2.22.0
|
|
16
|
+
---
|
|
17
|
+
* Update dependencies
|
|
18
|
+
|
|
19
|
+
v2.21.1
|
|
20
|
+
---
|
|
21
|
+
* Better error handling (#354)
|
|
22
|
+
|
|
4
23
|
v2.21.0
|
|
5
24
|
----
|
|
6
25
|
* Add `html-webpack-plugin-alter-asset-tags` event to allow plugins to adjust the script/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) [](https://david-dm.org/ampedandwired/html-webpack-plugin) [](https://travis-ci.org/ampedandwired/html-webpack-plugin) [](https://ci.appveyor.com/project/jantimon/html-webpack-plugin) [](https://github.com/Flet/semistandard) [](https://www.bithound.io/github/ampedandwired/html-webpack-plugin/master/dependencies/npm)
|
|
3
|
+
[](http://badge.fury.io/js/html-webpack-plugin) [](https://david-dm.org/ampedandwired/html-webpack-plugin) [](https://travis-ci.org/ampedandwired/html-webpack-plugin) [](https://ci.appveyor.com/project/jantimon/html-webpack-plugin) [](https://github.com/Flet/semistandard) [](https://www.bithound.io/github/ampedandwired/html-webpack-plugin/master/dependencies/npm) []()
|
|
4
4
|
|
|
5
5
|
[](https://nodei.co/npm/html-webpack-plugin/)
|
|
6
6
|
|
|
@@ -24,8 +24,7 @@ Migration guide from 1.x
|
|
|
24
24
|
[Changelog](https://github.com/ampedandwired/html-webpack-plugin/blob/master/CHANGELOG.md)
|
|
25
25
|
|
|
26
26
|
If you used the 1.x version please take a look at the [migration guide](https://github.com/ampedandwired/html-webpack-plugin/blob/master/migration.md)
|
|
27
|
-
|
|
28
|
-
See also issue [#186](https://github.com/ampedandwired/html-webpack-plugin/issues/186)
|
|
27
|
+
|
|
29
28
|
|
|
30
29
|
Basic Usage
|
|
31
30
|
-----------
|
|
@@ -63,7 +62,7 @@ This will generate a file `dist/index.html` containing the following:
|
|
|
63
62
|
If you have multiple webpack entry points, they will all be included with `script`
|
|
64
63
|
tags in the generated HTML.
|
|
65
64
|
|
|
66
|
-
If you have any
|
|
65
|
+
If you have any CSS assets in webpack's output (for example, CSS extracted
|
|
67
66
|
with the [ExtractTextPlugin](https://github.com/webpack/extract-text-webpack-plugin))
|
|
68
67
|
then these will be included with `<link>` tags in the HTML head.
|
|
69
68
|
|
|
@@ -75,12 +74,12 @@ Allowed values are as follows:
|
|
|
75
74
|
- `title`: The title to use for the generated HTML document.
|
|
76
75
|
- `filename`: The file to write the HTML to. Defaults to `index.html`.
|
|
77
76
|
You can specify a subdirectory here too (eg: `assets/admin.html`).
|
|
78
|
-
- `template`:
|
|
77
|
+
- `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.
|
|
79
78
|
- `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.
|
|
80
79
|
- `favicon`: Adds the given favicon path to the output html.
|
|
81
80
|
- `minify`: `{...} | false` Pass a [html-minifier](https://github.com/kangax/html-minifier#options-quick-reference) options object to minify the output.
|
|
82
81
|
- `hash`: `true | false` if `true` then append a unique webpack compilation hash to all
|
|
83
|
-
included scripts and
|
|
82
|
+
included scripts and CSS files. This is useful for cache busting.
|
|
84
83
|
- `cache`: `true | false` if `true` (default) try to emit the file only if it was changed.
|
|
85
84
|
- `showErrors`: `true | false` if `true` (default) errors details will be written into the html page.
|
|
86
85
|
- `chunks`: Allows you to add only some chunks (e.g. only the unit-test chunk)
|
|
@@ -105,6 +104,13 @@ Here's an example webpack config illustrating how to use these options:
|
|
|
105
104
|
}
|
|
106
105
|
```
|
|
107
106
|
|
|
107
|
+
FAQ
|
|
108
|
+
----
|
|
109
|
+
|
|
110
|
+
* [Why is my html minified?](https://github.com/ampedandwired/html-webpack-plugin/blob/master/docs/template-option.md)
|
|
111
|
+
* [Why is my `<% ... %>` template not working?](https://github.com/ampedandwired/html-webpack-plugin/blob/master/docs/template-option.md)
|
|
112
|
+
* [How can I use handlebars/pug/ejs as template engine](https://github.com/ampedandwired/html-webpack-plugin/blob/master/docs/template-option.md)
|
|
113
|
+
|
|
108
114
|
Generating Multiple HTML Files
|
|
109
115
|
------------------------------
|
|
110
116
|
To generate more than one HTML file, declare the plugin more than
|
|
@@ -129,16 +135,15 @@ once in your plugins array:
|
|
|
129
135
|
Writing Your Own Templates
|
|
130
136
|
--------------------------
|
|
131
137
|
If the default generated HTML doesn't meet your needs you can supply
|
|
132
|
-
your own template. The easiest way is to use the `
|
|
133
|
-
The html-webpack-plugin will automatically inject all necessary
|
|
138
|
+
your own template. The easiest way is to use the `template` option and pass a custom html file.
|
|
139
|
+
The html-webpack-plugin will automatically inject all necessary CSS, JS, manifest
|
|
134
140
|
and favicon files into the markup.
|
|
135
141
|
|
|
136
142
|
```javascript
|
|
137
143
|
plugins: [
|
|
138
144
|
new HtmlWebpackPlugin({
|
|
139
145
|
title: 'Custom template',
|
|
140
|
-
template: 'my-index.ejs', // Load a custom template (ejs by default
|
|
141
|
-
inject: 'body' // Inject all scripts into the body (this is the default so you can skip it)
|
|
146
|
+
template: 'my-index.ejs', // Load a custom template (ejs by default see the FAQ for details)
|
|
142
147
|
})
|
|
143
148
|
]
|
|
144
149
|
```
|
|
@@ -291,3 +296,13 @@ plugins: [
|
|
|
291
296
|
```
|
|
292
297
|
|
|
293
298
|
Note that the callback must be passed the htmlPluginData in order to pass this onto any other plugins listening on the same 'html-webpack-plugin-before-html-processing' event.
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
# Contribution
|
|
302
|
+
|
|
303
|
+
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.
|
|
304
|
+
This project uses the [semistandard code style](https://github.com/Flet/semistandard).
|
|
305
|
+
|
|
306
|
+
# License
|
|
307
|
+
|
|
308
|
+
This project is licensed under [MIT](https://github.com/ampedandwired/html-webpack-plugin/blob/master/LICENSE).
|
package/index.js
CHANGED
|
@@ -12,7 +12,7 @@ Promise.promisifyAll(fs);
|
|
|
12
12
|
function HtmlWebpackPlugin (options) {
|
|
13
13
|
// Default options
|
|
14
14
|
this.options = _.extend({
|
|
15
|
-
template: __dirname
|
|
15
|
+
template: path.join(__dirname, 'default_index.ejs'),
|
|
16
16
|
filename: 'index.html',
|
|
17
17
|
hash: false,
|
|
18
18
|
inject: true,
|
|
@@ -63,7 +63,7 @@ HtmlWebpackPlugin.prototype.apply = function (compiler) {
|
|
|
63
63
|
});
|
|
64
64
|
|
|
65
65
|
compiler.plugin('emit', function (compilation, callback) {
|
|
66
|
-
var applyPluginsAsyncWaterfall =
|
|
66
|
+
var applyPluginsAsyncWaterfall = self.applyPluginsAsyncWaterfall(compilation);
|
|
67
67
|
// Get all chunks
|
|
68
68
|
var chunks = self.filterChunks(compilation.getStats().toJson(), self.options.chunks, self.options.excludeChunks);
|
|
69
69
|
// Sort chunks
|
|
@@ -93,7 +93,7 @@ HtmlWebpackPlugin.prototype.apply = function (compiler) {
|
|
|
93
93
|
if (self.options.favicon) {
|
|
94
94
|
return self.addFileToAssets(self.options.favicon, compilation)
|
|
95
95
|
.then(function (faviconBasename) {
|
|
96
|
-
var publicPath = compilation.
|
|
96
|
+
var publicPath = compilation.mainTemplate.getPublicPath({hash: compilation.hash}) || '';
|
|
97
97
|
if (publicPath && publicPath.substr(-1) !== '/') {
|
|
98
98
|
publicPath += '/';
|
|
99
99
|
}
|
|
@@ -107,7 +107,7 @@ HtmlWebpackPlugin.prototype.apply = function (compiler) {
|
|
|
107
107
|
})
|
|
108
108
|
.then(function (compiledTemplate) {
|
|
109
109
|
// Allow to use a custom function / string instead
|
|
110
|
-
if (self.options.templateContent) {
|
|
110
|
+
if (self.options.templateContent !== undefined) {
|
|
111
111
|
return self.options.templateContent;
|
|
112
112
|
}
|
|
113
113
|
// Once everything is compiled evaluate the html factory
|
|
@@ -137,28 +137,33 @@ HtmlWebpackPlugin.prototype.apply = function (compiler) {
|
|
|
137
137
|
// Allow plugins to change the html before assets are injected
|
|
138
138
|
.then(function (html) {
|
|
139
139
|
var pluginArgs = {html: html, assets: assets, plugin: self, outputName: self.childCompilationOutputName};
|
|
140
|
-
return applyPluginsAsyncWaterfall('html-webpack-plugin-before-html-processing', pluginArgs)
|
|
141
|
-
.then(function () {
|
|
142
|
-
return pluginArgs.html;
|
|
143
|
-
});
|
|
140
|
+
return applyPluginsAsyncWaterfall('html-webpack-plugin-before-html-processing', pluginArgs);
|
|
144
141
|
})
|
|
145
|
-
.then(function (
|
|
142
|
+
.then(function (result) {
|
|
143
|
+
var html = result.html;
|
|
144
|
+
var assets = result.assets;
|
|
145
|
+
var chunks = result.chunks;
|
|
146
146
|
// Prepare script and link tags
|
|
147
147
|
var assetTags = self.generateAssetTags(assets);
|
|
148
148
|
var pluginArgs = {head: assetTags.head, body: assetTags.body, plugin: self, chunks: chunks, outputName: self.childCompilationOutputName};
|
|
149
149
|
// Allow plugins to change the assetTag definitions
|
|
150
150
|
return applyPluginsAsyncWaterfall('html-webpack-plugin-alter-asset-tags', pluginArgs)
|
|
151
|
-
.then(function () {
|
|
151
|
+
.then(function (result) {
|
|
152
152
|
// Add the stylesheets, scripts and so on to the resulting html
|
|
153
|
-
return self.postProcessHtml(html, assets, { body:
|
|
153
|
+
return self.postProcessHtml(html, assets, { body: result.body, head: result.head })
|
|
154
|
+
.then(function (html) {
|
|
155
|
+
return _.extend(result, {html: html, assets: assets});
|
|
156
|
+
});
|
|
154
157
|
});
|
|
155
158
|
})
|
|
156
159
|
// Allow plugins to change the html after assets are injected
|
|
157
|
-
.then(function (
|
|
160
|
+
.then(function (result) {
|
|
161
|
+
var html = result.html;
|
|
162
|
+
var assets = result.assets;
|
|
158
163
|
var pluginArgs = {html: html, assets: assets, plugin: self, outputName: self.childCompilationOutputName};
|
|
159
164
|
return applyPluginsAsyncWaterfall('html-webpack-plugin-after-html-processing', pluginArgs)
|
|
160
|
-
.then(function () {
|
|
161
|
-
return
|
|
165
|
+
.then(function (result) {
|
|
166
|
+
return result.html;
|
|
162
167
|
});
|
|
163
168
|
})
|
|
164
169
|
.catch(function (err) {
|
|
@@ -592,7 +597,7 @@ HtmlWebpackPlugin.prototype.getFullTemplatePath = function (template, context) {
|
|
|
592
597
|
}
|
|
593
598
|
// Resolve template path
|
|
594
599
|
return template.replace(
|
|
595
|
-
/(
|
|
600
|
+
/([!])([^\/\\][^!\?]+|[^\/\\!?])($|\?.+$)/,
|
|
596
601
|
function (match, prefix, filepath, postfix) {
|
|
597
602
|
return prefix + path.resolve(filepath) + postfix;
|
|
598
603
|
});
|
|
@@ -612,4 +617,21 @@ HtmlWebpackPlugin.prototype.getAssetFiles = function (assets) {
|
|
|
612
617
|
return files;
|
|
613
618
|
};
|
|
614
619
|
|
|
620
|
+
/**
|
|
621
|
+
* Helper to promisify compilation.applyPluginsAsyncWaterfall that returns
|
|
622
|
+
* a function that helps to merge given plugin arguments with processed ones
|
|
623
|
+
*/
|
|
624
|
+
HtmlWebpackPlugin.prototype.applyPluginsAsyncWaterfall = function (compilation) {
|
|
625
|
+
var promisedApplyPluginsAsyncWaterfall = Promise.promisify(compilation.applyPluginsAsyncWaterfall, {context: compilation});
|
|
626
|
+
return function (eventName, pluginArgs) {
|
|
627
|
+
return promisedApplyPluginsAsyncWaterfall(eventName, pluginArgs)
|
|
628
|
+
.then(function (result) {
|
|
629
|
+
if (!result) {
|
|
630
|
+
compilation.warnings.push(new Error('Using html-webpack-plugin-after-html-processing without returning a result is deprecated.'));
|
|
631
|
+
}
|
|
632
|
+
return _.extend(pluginArgs, result);
|
|
633
|
+
});
|
|
634
|
+
};
|
|
635
|
+
};
|
|
636
|
+
|
|
615
637
|
module.exports = HtmlWebpackPlugin;
|
package/lib/compiler.js
CHANGED
|
@@ -68,18 +68,6 @@ module.exports.compileTemplate = function compileTemplate (template, context, ou
|
|
|
68
68
|
// Compile and return a promise
|
|
69
69
|
return new Promise(function (resolve, reject) {
|
|
70
70
|
childCompiler.runAsChild(function (err, entries, childCompilation) {
|
|
71
|
-
// Replace [hash] placeholders in filename
|
|
72
|
-
var outputName = compilation.mainTemplate.applyPluginsWaterfall('asset-path', outputOptions.filename, {
|
|
73
|
-
hash: childCompilation.hash,
|
|
74
|
-
chunk: entries[0]
|
|
75
|
-
});
|
|
76
|
-
// Restore the parent compilation to the state like it
|
|
77
|
-
// was before the child compilation
|
|
78
|
-
compilation.assets[outputName] = assetsBeforeCompilation[outputName];
|
|
79
|
-
if (assetsBeforeCompilation[outputName] === undefined) {
|
|
80
|
-
// If it wasn't there - delete it
|
|
81
|
-
delete compilation.assets[outputName];
|
|
82
|
-
}
|
|
83
71
|
// Resolve / reject the promise
|
|
84
72
|
if (childCompilation && childCompilation.errors && childCompilation.errors.length) {
|
|
85
73
|
var errorDetails = childCompilation.errors.map(function (error) {
|
|
@@ -89,6 +77,18 @@ module.exports.compileTemplate = function compileTemplate (template, context, ou
|
|
|
89
77
|
} else if (err) {
|
|
90
78
|
reject(err);
|
|
91
79
|
} else {
|
|
80
|
+
// Replace [hash] placeholders in filename
|
|
81
|
+
var outputName = compilation.mainTemplate.applyPluginsWaterfall('asset-path', outputOptions.filename, {
|
|
82
|
+
hash: childCompilation.hash,
|
|
83
|
+
chunk: entries[0]
|
|
84
|
+
});
|
|
85
|
+
// Restore the parent compilation to the state like it
|
|
86
|
+
// was before the child compilation
|
|
87
|
+
compilation.assets[outputName] = assetsBeforeCompilation[outputName];
|
|
88
|
+
if (assetsBeforeCompilation[outputName] === undefined) {
|
|
89
|
+
// If it wasn't there - delete it
|
|
90
|
+
delete compilation.assets[outputName];
|
|
91
|
+
}
|
|
92
92
|
resolve({
|
|
93
93
|
// Hash of the template entry point
|
|
94
94
|
hash: entries[0].hash,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "html-webpack-plugin",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.24.0",
|
|
4
4
|
"description": "Simplifies creation of HTML files to serve your webpack bundles",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -30,31 +30,39 @@
|
|
|
30
30
|
"url": "https://github.com/ampedandwired/html-webpack-plugin/issues"
|
|
31
31
|
},
|
|
32
32
|
"homepage": "https://github.com/ampedandwired/html-webpack-plugin",
|
|
33
|
+
"semistandard": {
|
|
34
|
+
"ignore": [
|
|
35
|
+
"examples/*/dist/**/*.*"
|
|
36
|
+
]
|
|
37
|
+
},
|
|
33
38
|
"devDependencies": {
|
|
34
|
-
"appcache-webpack-plugin": "^1.
|
|
35
|
-
"css-loader": "^0.
|
|
36
|
-
"dir-compare": "1.0
|
|
37
|
-
"es6-promise": "^
|
|
39
|
+
"appcache-webpack-plugin": "^1.3.0",
|
|
40
|
+
"css-loader": "^0.25.0",
|
|
41
|
+
"dir-compare": "1.2.0",
|
|
42
|
+
"es6-promise": "^4.0.5",
|
|
38
43
|
"extract-text-webpack-plugin": "^1.0.1",
|
|
39
|
-
"file-loader": "^0.
|
|
40
|
-
"html-loader": "^0.4.
|
|
44
|
+
"file-loader": "^0.9.0",
|
|
45
|
+
"html-loader": "^0.4.4",
|
|
41
46
|
"jade": "^1.11.0",
|
|
42
47
|
"jade-loader": "^0.8.0",
|
|
43
|
-
"jasmine": "^2.
|
|
44
|
-
"rimraf": "^2.5.
|
|
45
|
-
"semistandard": "
|
|
48
|
+
"jasmine": "^2.5.2",
|
|
49
|
+
"rimraf": "^2.5.4",
|
|
50
|
+
"semistandard": "8.0.0",
|
|
46
51
|
"style-loader": "^0.13.1",
|
|
47
52
|
"underscore-template-loader": "^0.7.3",
|
|
48
53
|
"url-loader": "^0.5.7",
|
|
49
|
-
"webpack": "^1.13.
|
|
54
|
+
"webpack": "^1.13.2",
|
|
50
55
|
"webpack-recompilation-simulator": "^1.3.0"
|
|
51
56
|
},
|
|
52
57
|
"dependencies": {
|
|
53
|
-
"bluebird": "^3.
|
|
54
|
-
"html-minifier": "^
|
|
55
|
-
"loader-utils": "^0.2.
|
|
56
|
-
"lodash": "^4.
|
|
57
|
-
"pretty-error": "^2.0.
|
|
58
|
+
"bluebird": "^3.4.6",
|
|
59
|
+
"html-minifier": "^3.1.0",
|
|
60
|
+
"loader-utils": "^0.2.16",
|
|
61
|
+
"lodash": "^4.16.4",
|
|
62
|
+
"pretty-error": "^2.0.2",
|
|
58
63
|
"toposort": "^1.0.0"
|
|
64
|
+
},
|
|
65
|
+
"peerDependencies": {
|
|
66
|
+
"webpack": "1 || ^2.1.0-beta"
|
|
59
67
|
}
|
|
60
68
|
}
|