ag-grid is proud to partner with webpack

CompressionWebpackPlugin

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

Install

npm i -D compression-webpack-plugin

Usage

webpack.config.js

const CompressionPlugin = require("compression-webpack-plugin")

module.exports = {
  plugins: [
    new CompressionPlugin(...options)
  ]
}

Options

Name
Type
Default
Description
Name
test
Type
{RegExp}
Default
.
Description
All assets matching this {RegExp} are processed
Name
asset
Type
{String}
Default
[path].gz[query]
Description
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
Name
filename
Type
{Function}
Default
false
Description
A {Function} (asset) => asset which receives the asset name (after processing asset option) and returns the new asset name
Name
algorithm
Type
{String|Function}
Default
gzip
Description
Can be (buffer, cb) => cb(buffer) or if a {String}is used the algorithm is taken fromzlib`
Name
threshold
Type
{Number}
Default
0
Description
Only assets bigger than this size are processed. In bytes.
Name
minRatio
Type
{Number}
Default
0.8
Description
Only assets that compress better that this ratio are processed
Name
deleteOriginalAssets
Type
{Boolean}
Default
false
Description
Whether to delete the original assets or not

##

webpack.config.js

[
  new CompressionPlugin({
    test: /\.js/
  })
]

asset

webpack.config.js

[
  new CompressionPlugin({
    asset: '[path].gz[query]'
  })
]

filename

webpack.config.js

[
  new CompressionPlugin({
    filename (asset) {
      asset = 'rename'
      return asset
    }
  })
]

algorithm

webpack.config.js

[
  new CompressionPlugin({
    algorithm: 'gzip'
  })
]

threshold

webpack.config.js

[
  new CompressionPlugin({
    threshold: 0
  })
]

minRatio

webpack.config.js

[
  new CompressionPlugin({
    minRatio: 0.8
  })
]

deleteOriginalAssets

webpack.config.js

[
  new CompressionPlugin({
    deleteOriginalAssets: true
  })
]

Maintainers


    Joshua Wiens


    Juho Vepsäläinen


    Michael Ciniawsky


    Alexander Krasnoyarov