compress.ts 757 B

123456789101112131415161718192021222324252627282930
  1. /**
  2. * Used to package and output gzip. Note that this does not work properly in Vite, the specific reason is still being investigated
  3. * https://github.com/anncwb/vite-plugin-compression
  4. */
  5. import type { Plugin } from 'vite';
  6. import compressPlugin from 'vite-plugin-compression';
  7. export function configCompressPlugin(compress: 'gzip' | 'brotli' | 'none'): Plugin | Plugin[] {
  8. const compressList = compress.split(',');
  9. const plugins: Plugin[] = [];
  10. if (compressList.includes('gzip')) {
  11. plugins.push(
  12. compressPlugin({
  13. ext: '.gz',
  14. })
  15. );
  16. }
  17. if (compressList.includes('brotli')) {
  18. plugins.push(
  19. compressPlugin({
  20. ext: '.br',
  21. algorithm: 'brotliCompress',
  22. })
  23. );
  24. }
  25. return plugins;
  26. }