compress.ts 868 B

1234567891011121314151617181920212223242526272829303132333435
  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 { PluginOption } from 'vite';
  6. import compressPlugin from 'vite-plugin-compression';
  7. export function configCompressPlugin(
  8. compress: 'gzip' | 'brotli' | 'none',
  9. deleteOriginFile = false,
  10. ): PluginOption | PluginOption[] {
  11. const compressList = compress.split(',');
  12. const plugins: PluginOption[] = [];
  13. if (compressList.includes('gzip')) {
  14. plugins.push(
  15. compressPlugin({
  16. ext: '.gz',
  17. deleteOriginFile,
  18. }),
  19. );
  20. }
  21. if (compressList.includes('brotli')) {
  22. plugins.push(
  23. compressPlugin({
  24. ext: '.br',
  25. algorithm: 'brotliCompress',
  26. deleteOriginFile,
  27. }),
  28. );
  29. }
  30. return plugins;
  31. }