Add minification again

This commit is contained in:
Jan Nicklas 2015-05-18 15:30:42 +02:00 committed by Jan Nicklas
parent c8a69255b9
commit d82bd52e2f
3 changed files with 26 additions and 6 deletions

View File

@ -1,5 +1,5 @@
HTML Webpack Plugin
===================
===================
[![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) [![bitHound Score](https://www.bithound.io/github/ampedandwired/html-webpack-plugin/badges/score.svg)](https://www.bithound.io/github/ampedandwired/html-webpack-plugin) [![Build status](https://travis-ci.org/ampedandwired/html-webpack-plugin.svg)](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.

View File

@ -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
}
})
]
};

View File

@ -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;
}
});
};