Skip to content

Commit

Permalink
Add minification again
Browse files Browse the repository at this point in the history
  • Loading branch information
jantimon committed May 18, 2015
1 parent d5160fe commit a815133
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -63,8 +63,8 @@ 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`.
- `compile`: if `true` the template will be processed using the [blueimp template engine](https://github.com/blueimp/JavaScript-Templates).
- `inject`: Inject all assets into the given `template` or `templateContent`.
- `favicon`: Adds the given favicon path to the output html.
- `minify`: Set to true or pass a [html-minifier](https://github.com/kangax/html-minifier#options-quick-reference) options object to minify the output.
Expand Down
9 changes: 8 additions & 1 deletion example/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 16 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function HtmlWebpackPlugin(options) {
inject: true,
compile: true,
favicon: false,
minify: false,
chunks: 'all',
excludeChunks: [],
title: 'Webpack App'
Expand Down Expand Up @@ -142,16 +143,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;
}
});
};

Expand Down

0 comments on commit a815133

Please sign in to comment.