Skip to content

Prepare Brotli-compressed versions of assets to serve them with Content-Encoding: br

License

Notifications You must be signed in to change notification settings

nrandell/brotli-gzip-webpack-plugin

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

brotli gzip plugin for webpack

This is a fork of brotli-webpack-plugin that supports both gzip and brotli compression. I'm using it because the official compression plugin no longer works and there appears to be delays in patches. I'm using it to build both gzip and brotli compressed files for serving over ASP.Net core using the CompressedStaticFiles middleware.

This plugin compresses assets with Brotli compression algorithm using iltorb library for serving it with ngx_brotli or such.

Installation

npm install --save-dev brotli-gzip-webpack-plugin

Usage

var BrotliGzipPlugin = require('brotli-gzip-webpack-plugin');
module.exports = {
	plugins: [
		new BrotliGzipPlugin({
			asset: '[path].br[query]',
			algorithm: 'brotli',
			test: /\.(js|css|html|svg)$/,
			threshold: 10240,
			minRatio: 0.8
		}),
		new BrotliGzipPlugin({
			asset: '[path].gz[query]',
			algorithm: 'gzip',
			test: /\.(js|css|html|svg)$/,
			threshold: 10240,
			minRatio: 0.8
		})
	]
}

Arguments:

  • asset: The target asset name. Defaults to '[path].br[query]'.
    • [file] is replaced with the original asset file name.
    • [fileWithoutExt] is replaced with the file name minus its extension, e.g. the style of style.css.
    • [ext] is replaced with the file name extension, e.g. the css of style.css.
    • [path] is replaced with the path of the original asset.
    • [query] is replaced with the query.
  • test: All assets matching this RegExp are processed. Defaults to every asset.
  • threshold: Only assets bigger than this size (in bytes) are processed. Defaults to 0.
  • minRatio: Only assets that compress better that this ratio are processed. Defaults to 0.8.

Optional arguments for Brotli (see iltorb doc for details):

  • mode: Default: 0,
  • quality: Default: 11,
  • lgwin: Default: 22,
  • lgblock: Default: 0,
  • enable_dictionary: Default: true,
  • enable_transforms: Default: false,
  • greedy_block_split: Default: false,
  • enable_context_modeling: Default: false

License

Heavily copy-pasted from webpack/compression-webpack-plugin by Tobias Koppers.

Licensed under MIT.

About

Prepare Brotli-compressed versions of assets to serve them with Content-Encoding: br

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%