compression.js 650 B

123456789101112131415161718192021222324252627282930
  1. import compression from 'vite-plugin-compression'
  2. export default function createCompression(env) {
  3. const {
  4. VITE_BUILD_COMPRESS
  5. } = env
  6. const plugin = []
  7. if (VITE_BUILD_COMPRESS) {
  8. const compressList = VITE_BUILD_COMPRESS.split(',')
  9. if (compressList.includes('gzip')) {
  10. // http://doc.ruoyi.vip/ruoyi-vue/other/faq.html#使用gzip解压缩静态文件
  11. plugin.push(
  12. compression({
  13. ext: '.gz',
  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. }