Appearance
gzip压缩
vue.config.js文件
优化打包体积,在性能方面可以起到优化作用
js
npm i compression-webpack-plugin --save-dev
npm i compression-webpack-plugin --save-dev
js
const { defineConfig } = require("@vue/cli-service");
const CompressionWebpackPlugin = require("compression-webpack-plugin");
module.exports = defineConfig({
configureWebpack: (config) => {
if (process.env. NODE_ENV === "production") {
return {
plugins: [
new CompressionWebpackPlugin({
test: /\.js$|\.html$|\.css/, // 压缩文件的后缀
threshold: 10240, // 对超过 1k 的文件进行压缩
deleteOriginalAssets: false, // 不需要保留压缩前文件
}),
],
};
}
},
});
const { defineConfig } = require("@vue/cli-service");
const CompressionWebpackPlugin = require("compression-webpack-plugin");
module.exports = defineConfig({
configureWebpack: (config) => {
if (process.env. NODE_ENV === "production") {
return {
plugins: [
new CompressionWebpackPlugin({
test: /\.js$|\.html$|\.css/, // 压缩文件的后缀
threshold: 10240, // 对超过 1k 的文件进行压缩
deleteOriginalAssets: false, // 不需要保留压缩前文件
}),
],
};
}
},
});