Newer
Older
DH_Apicture / vite / plugins / compression.js
@zhangqy zhangqy on 29 Nov 899 bytes first commit
  1. import compression from 'vite-plugin-compression';
  2.  
  3. export default function createCompression(env) {
  4. const { VITE_BUILD_COMPRESS } = env;
  5. const plugin = [];
  6. if (VITE_BUILD_COMPRESS) {
  7. const compressList = VITE_BUILD_COMPRESS.split(',');
  8. if (compressList.includes('gzip')) {
  9. // http://doc.ruoyi.vip/ruoyi-vue/other/faq.html#使用gzip解压缩静态文件
  10. plugin.push(
  11. compression({
  12. deleteOriginFile: false,
  13. threshold: 1024 * 300, // 对大于300kb的文件进行压缩
  14. algorithm: 'gzip', // 采用的压缩算法,默认是 gzip
  15. ext: '.gz', // 生成的压缩包后缀
  16. })
  17. );
  18. }
  19. if (compressList.includes('brotli')) {
  20. plugin.push(
  21. compression({
  22. ext: '.br',
  23. algorithm: 'brotliCompress',
  24. deleteOriginFile: false,
  25. })
  26. );
  27. }
  28. }
  29. return plugin;
  30. }