Add minification again
This commit is contained in:
parent
c8a69255b9
commit
d82bd52e2f
|
|
@ -1,5 +1,5 @@
|
|||
HTML Webpack Plugin
|
||||
===================
|
||||
===================
|
||||
[](http://badge.fury.io/js/html-webpack-plugin) [](https://david-dm.org/ampedandwired/html-webpack-plugin) [](https://www.bithound.io/github/ampedandwired/html-webpack-plugin) [](https://travis-ci.org/ampedandwired/html-webpack-plugin)
|
||||
|
||||
This is a [webpack](http://webpack.github.io/) plugin that simplifies creation of HTML files to serve your
|
||||
|
|
@ -63,8 +63,7 @@ Allowed values are as follows:
|
|||
- `title`: The title to use for the generated HTML document.
|
||||
- `filename`: The file to write the HTML to. Defaults to `index.html`.
|
||||
You can specify a subdirectory here too (eg: `assets/admin.html`).
|
||||
- `template`: A html template (supports [blueimp templates](https://github.com/blueimp/JavaScript-Templates)).
|
||||
- `templateContent`: A html string or a function returning the html (supports [blueimp templates](https://github.com/blueimp/JavaScript-Templates)).
|
||||
- `template`: Path to the template. Supports loaders e.g. `html!./index.html`.
|
||||
- `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.
|
||||
- `favicon`: Adds the given favicon path to the output html.
|
||||
- `minify`: `{...} | false` Pass a [html-minifier](https://github.com/kangax/html-minifier#options-quick-reference) options object to minify the output.
|
||||
|
|
|
|||
|
|
@ -8,7 +8,14 @@ module.exports = {
|
|||
},
|
||||
plugins: [
|
||||
new HtmlWebpackPlugin({
|
||||
favicon: 'favicon.ico'
|
||||
favicon: 'favicon.ico',
|
||||
minify: {
|
||||
removeComments: true,
|
||||
collapseWhitespace: true,
|
||||
conservativeCollapse: false,
|
||||
minifyJS: true,
|
||||
minifyCSS: true
|
||||
}
|
||||
})
|
||||
]
|
||||
};
|
||||
18
index.js
18
index.js
|
|
@ -22,6 +22,7 @@ function HtmlWebpackPlugin(options) {
|
|||
inject: true,
|
||||
compile: true,
|
||||
favicon: false,
|
||||
minify: false,
|
||||
chunks: 'all',
|
||||
excludeChunks: [],
|
||||
title: 'Webpack App'
|
||||
|
|
@ -141,16 +142,29 @@ HtmlWebpackPlugin.prototype.postProcessHtml = function(html, compilation) {
|
|||
}
|
||||
};
|
||||
if (self.options.compile === true) {
|
||||
html = tmpl(html, templateParams);
|
||||
return tmpl(html, templateParams);
|
||||
} else {
|
||||
return html;
|
||||
}
|
||||
})
|
||||
// Inject
|
||||
.then(function() {
|
||||
.then(function(html) {
|
||||
if (self.options.inject) {
|
||||
return self.injectAssetsIntoHtml(html, assets);
|
||||
} else {
|
||||
return html;
|
||||
}
|
||||
})
|
||||
// Minify
|
||||
.then(function(html) {
|
||||
if (self.options.minify) {
|
||||
var minify = require('html-minifier').minify;
|
||||
// If `options.minify` is set to true use the default minify options
|
||||
var minifyOptions = _.isObject(self.options.minify) ? self.options.minify : {};
|
||||
return minify(html, minifyOptions);
|
||||
} else {
|
||||
return html;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue