Prepare compressed versions of assets to serve them with Content-Encoding
npm i -D compression-webpack-plugin
webpack.config.js
const CompressionPlugin = require("compression-webpack-plugin")
module.exports = {
plugins: [
new CompressionPlugin(...options)
]
}
{RegExp|Array<RegExp>}
.
{RegExp|Array<RegExp>}
are processed
{String}
[path].gz[query]
[file]
is replaced with the original asset. [path]
is replaced with the path of the original asset and [query]
with the query
{Function}
false
{Function}
(asset) => asset
which receives the asset name (after processing asset
option) and returns the new asset name
{String|Function}
gzip
(buffer, cb) => cb(buffer)
or if a {String}
is used the algorithm is taken from zlib
{Number}
0
{Number}
0.8
{Boolean}
false
##
webpack.config.js
[
new CompressionPlugin({
test: /\.js/
})
]
include
webpack.config.js
[
new CompressionPlugin({
include: /\/includes/
})
]
exclude
webpack.config.js
[
new CompressionPlugin({
exclude: /\/excludes/
})
]
cache
webpack.config.js
[
new CompressionPlugin({
cache: true
})
]
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
})
]
|
|
|
|