compress.ts 882 B

1234567891011121314151617181920212223242526272829303132333435363738
  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,
  9. deleteOriginFile = false,
  10. }: {
  11. compress: string;
  12. deleteOriginFile?: boolean;
  13. }): PluginOption[] {
  14. const compressList = compress.split(',');
  15. const plugins: PluginOption[] = [];
  16. if (compressList.includes('gzip')) {
  17. plugins.push(
  18. compressPlugin({
  19. ext: '.gz',
  20. deleteOriginFile,
  21. }),
  22. );
  23. }
  24. if (compressList.includes('brotli')) {
  25. plugins.push(
  26. compressPlugin({
  27. ext: '.br',
  28. algorithm: 'brotliCompress',
  29. deleteOriginFile,
  30. }),
  31. );
  32. }
  33. return plugins;
  34. }