compress.ts 859 B

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