compression.ts 947 B

1234567891011121314151617181920212223242526272829
  1. import { PluginOption } from 'vite';
  2. import compression from 'vite-plugin-compression';
  3. export default function createCompression(env: Record<string, string>) {
  4. const { VITE_BUILD_COMPRESS } = env;
  5. const plugin: PluginOption[] = [];
  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. ext: '.gz',
  13. deleteOriginFile: false,
  14. })
  15. );
  16. }
  17. if (compressList.includes('brotli')) {
  18. plugin.push(
  19. compression({
  20. ext: '.br',
  21. algorithm: 'brotliCompress',
  22. deleteOriginFile: false,
  23. })
  24. );
  25. }
  26. }
  27. return plugin;
  28. }