|
|
6 meses atrás | |
|---|---|---|
| .. | ||
| dist | 6 meses atrás | |
| CHANGELOG.md | 6 meses atrás | |
| LICENSE | 6 meses atrás | |
| README.md | 6 meses atrás | |
| package.json | 6 meses atrás | |
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)
]
}
| Name | Type | Default | Description |
|---|---|---|---|
test |
{RegExp\|Array<RegExp>} |
. |
All assets matching this {RegExp\|Array<RegExp>} are processed |
include |
{RegExp\|Array<RegExp>} |
undefined |
Files to include |
exclude |
{RegExp\|Array<RegExp>} |
undefined |
Files to exclude |
cache |
{Boolean\|String} |
false |
Enable file caching |
asset |
{String} |
[path].gz[query] |
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 |
filename |
{Function} |
false |
A {Function} (asset) => asset which receives the asset name (after processing asset option) and returns the new asset name |
algorithm |
{String\|Function} |
gzip |
Can be (buffer, cb) => cb(buffer) or if a {String} is used the algorithm is taken from zlib |
threshold |
{Number} |
0 |
Only assets bigger than this size are processed. In bytes. |
minRatio |
{Number} |
0.8 |
Only assets that compress better than this ratio are processed |
deleteOriginalAssets |
{Boolean} |
false |
Whether to delete the original assets or not |
testwebpack.config.js
[
new CompressionPlugin({
test: /\.js/
})
]
includewebpack.config.js
[
new CompressionPlugin({
include: /\/includes/
})
]
excludewebpack.config.js
[
new CompressionPlugin({
exclude: /\/excludes/
})
]
cachewebpack.config.js
[
new CompressionPlugin({
cache: true
})
]
assetwebpack.config.js
[
new CompressionPlugin({
asset: '[path].gz[query]'
})
]
filenamewebpack.config.js
[
new CompressionPlugin({
filename (asset) {
asset = 'rename'
return asset
}
})
]
algorithmwebpack.config.js
[
new CompressionPlugin({
algorithm: 'gzip'
})
]
thresholdwebpack.config.js
[
new CompressionPlugin({
threshold: 0
})
]
minRatiowebpack.config.js
[
new CompressionPlugin({
minRatio: 0.8
})
]
deleteOriginalAssetswebpack.config.js
[
new CompressionPlugin({
deleteOriginalAssets: true
})
]
Joshua Wiens
|
Juho Vepsäläinen
|
Michael Ciniawsky
|
Alexander Krasnoyarov
|