html-compression-webpack-plugin

0.3.0 • Public • Published

HTML compression plugin for webpack

Info

The compression-webpack-plugin didn't compress HTML files. This plugin aims to solve that.

Usage

Credits to @sokra for the code from compression-webpack-plugin (https://github.com/webpack/compression-webpack-plugin) and other that contributed to it. Link to NPM: https://www.npmjs.com/package/html-compression-webpack-plugin

var HTMLCompressionPlugin = require("html-compression-webpack-plugin");
module.exports = {
    plugins: [
        new HTMLCompressionPlugin({
            testHTML: /\.html$/,
            test: /.*\.(css|js)$/i,
            asset: '[path].gz',
            algorithm: 'gzip',
            threshold: 0,
            minRatio: 0.0,
            deleteOriginalAssets: true
    })
    ]
}

Arguments:

  • asset: The target asset name. [file] is replaced with the original asset. [path] is replaced with the path of the original asset and [query] with the query. Defaults to "[path].gz[query]"
  • algorithm: Can be a function(buf, callback) or a string. For a string the algorithm is taken from zlib (or zopfli for zopfli). Defaults to "gzip".
  • deleteOriginalAssets: Whether to delete the original assets or not. Defaults to false.
  • test: All assets matching this RegExp are processed. Defaults to /.*\.(js|css)$/i
  • testHTML: All assets matching this RegExp are processed. This will happen in the emit phase. Defaults to /\.html$/
  • threshold: Only assets bigger than this size are processed. In bytes. Defaults to 0.
  • minRatio: Only assets that compress better that this ratio are processed. Defaults to 0.8.

Option Arguments for Zopfli (see node-zopfli doc for details):

  • verbose: Default: false,
  • verbose_more: Default: false,
  • numiterations: Default: 15,
  • blocksplitting: Default: true,
  • blocksplittinglast: Default: false,
  • blocksplittingmax: Default: 15

Example

To try out the example:

node example/run-to-bundle-example-project.js

The resulting files will be created example/build folder.

License

MIT (http://www.opensource.org/licenses/mit-license.php)

Readme

Keywords

none

Package Sidebar

Install

npm i html-compression-webpack-plugin

Weekly Downloads

1

Version

0.3.0

License

none

Last publish

Collaborators

  • tomdebacker