https://github.com/vbenjs/vite-plugin-compression
 安装所需依赖
yarn add vite-plugin-compression -D
 
压缩前

压缩后

 使用
 vite.config.ts
import viteCompression from 'vite-plugin-compression'
export default defineConfig({
  plugins: [
    vue(),
    viteCompression({
      verbose: true, // 是否在控制台输出压缩结果
      disable: false, // 是否禁用
      threshold: 10240, // 体积大于 threshold 才会被压缩,单位 b
      algorithm: 'gzip', // 压缩算法,可选 [ 'gzip' , 'brotliCompress' ,'deflate' , 'deflateRaw']
      ext: '.gz', // 生成的压缩包后缀
      deleteOriginFile: false //压缩后是否删除源文件
    }),
  ]
})
 
nginx配置
   location / {
       root   /data/nginx/html/admin;
       index  index.html index.htm;
       try_files $uri $uri/ /index.html;
       gzip_static on; 
   }
 
打开浏览器,查看响应头content-encoding : gzip说明配置成功了
 


















