vue 开启gzip压缩配置
程序员文章站
2022-03-23 11:19:01
1、安装:compression-webpack-pluginnpm install compression-webpack-plugin --save-dev2、vue.config.js配置const CompressionPlugin = require("compression-webpack-plugin");const productionGzipExtensions = /\.(js|css|json|txt|html|ico|svg)(\?.*)?$/i;module.export...
1、安装:compression-webpack-plugin
npm install compression-webpack-plugin --save-dev
2、vue.config.js配置
const CompressionPlugin = require("compression-webpack-plugin");
const productionGzipExtensions = /\.(js|css|json|txt|html|ico|svg)(\?.*)?$/i;
module.exports = {
configureWebpack: {
plugins: [
new CompressionPlugin({
filename: "[path].gz[query]",
algorithm: "gzip",
test: productionGzipExtensions,
// 只处理大于xx字节 的文件,默认:0
threshold: 10240,
// 示例:一个1024b大小的文件,压缩后大小为768b,minRatio : 0.75
minRatio: 0.8, // 默认: 0.8
// 是否删除源文件,默认: false
deleteOriginalAssets: false
})
]
}
};
本文地址:https://blog.csdn.net/sslcsq/article/details/109361900