compression.js 809 B

123456789101112131415161718192021222324252627282930
  1. import compression from 'vite-plugin-compression'
  2. export default function createCompression(env) {
  3. const { VITE_BUILD_COMPRESS } = env
  4. const plugin = []
  5. if (VITE_BUILD_COMPRESS) {
  6. const compressList = VITE_BUILD_COMPRESS.split(',')
  7. if (compressList.includes('gzip')) {
  8. // http://doc.ruoyi.vip/ruoyi-vue/other/faq.html#使用gzip解压缩静态文件
  9. plugin.push(
  10. compression({
  11. algorithm: 'gzip',
  12. threshold: 10240,//>=10kb的文件进行压缩
  13. verbose: false,
  14. deleteOriginFile: false
  15. })
  16. )
  17. }
  18. if (compressList.includes('brotli')) {
  19. plugin.push(
  20. compression({
  21. ext: '.br',
  22. algorithm: 'brotliCompress',
  23. deleteOriginFile: false
  24. })
  25. )
  26. }
  27. }
  28. return plugin
  29. }