Skip to content

Commit

Permalink
feat(webpack): add compression plugin
Browse files Browse the repository at this point in the history
* Compresses `*.css`, `*.html`, `*.js` and `*.map` build assets
* Uses gzip with maximum compression level - 9

Closes linnovate#234
  • Loading branch information
antonmoiseev committed Jan 19, 2016
1 parent 54c29ee commit f9b9cc9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"bluebird": "*",
"blueimp-tmpl": "*",
"colors": "^1.1.2",
"compression-webpack-plugin": "^0.2.0",
"copy-webpack-plugin": "^0.3.3",
"css-loader": "^0.23.0",
"enhanced-resolve": "0.9.1",
Expand Down
13 changes: 12 additions & 1 deletion webpack.prod.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Helper: root(), and rootDir() are defined at the bottom
*/
var path = require('path');
var zlib = require('zlib');
// Webpack Plugins
var webpack = require('webpack');
var ProvidePlugin = require('webpack/lib/ProvidePlugin');
Expand All @@ -12,6 +13,7 @@ var OccurenceOrderPlugin = require('webpack/lib/optimize/OccurenceOrderPlugin');
var DedupePlugin = require('webpack/lib/optimize/DedupePlugin');
var UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin');
var CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin');
var CompressionPlugin = require('compression-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var WebpackMd5Hash = require('webpack-md5-hash');
Expand Down Expand Up @@ -147,8 +149,13 @@ module.exports = {
//mangle: {
// screw_ie8 : true
//}
})
}),
// include uglify in production
new CompressionPlugin({
algorithm: gzipMaxLevel,
regExp: /\.css$|\.html$|\.js$|\.map$/,
threshold: 2 * 1024
})
],
// Other module loader config
tslint: {
Expand Down Expand Up @@ -179,3 +186,7 @@ function rootNode(args) {
args = Array.prototype.slice.call(arguments, 0);
return root.apply(path, ['node_modules'].concat(args));
}

function gzipMaxLevel(buffer, callback) {
return zlib['gzip'](buffer, {level: 9}, callback)
}

0 comments on commit f9b9cc9

Please sign in to comment.