提供带 Content-Encoding 编码的压缩版的资源
npm i -D compression-webpack-plugin
webpack.config.js
const CompressionPlugin = require("compression-webpack-plugin")
module.exports = {
plugins: [
new CompressionPlugin(...options)
]
}
test
{RegExp}
.
{RegExp}
的资源
asset
{String}
[path].gz[query]
[file]
会被替换成原资源。[path]
会被替换成原资源路径,[query]
替换成原查询字符串
filename
{Function}
false
{Function}
(asset) => asset
函数,接收原资源名(通过 asset
选项)返回新资源名
algorithm
{String|Function}
gzip
(buffer, cb) => cb(buffer)
或者是使用 zlib
里面的算法的 {String}
threshold
{Number}
0
minRatio
{Number}
0.8
deleteOriginalAssets
{Boolean}
false
test
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
})
]
|
|
|
|