compress.ts 704 B

1234567891011121314151617181920212223242526272829
  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. */
  4. import type { Plugin } from 'vite';
  5. import compressPlugin from 'vite-plugin-compression';
  6. export function configCompressPlugin(compress: 'gzip' | 'brotli' | 'none'): Plugin | Plugin[] {
  7. const compressList = compress.split(',');
  8. const plugins: Plugin[] = [];
  9. if (compressList.includes('gzip')) {
  10. plugins.push(
  11. compressPlugin({
  12. ext: '.gz',
  13. })
  14. );
  15. }
  16. if (compressList.includes('brotli')) {
  17. plugins.push(
  18. compressPlugin({
  19. ext: '.br',
  20. algorithm: 'brotliCompress',
  21. })
  22. );
  23. }
  24. return plugins;
  25. }