compress.ts 781 B

12345678910111213141516171819202122232425262728293031323334
  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. * gzip压缩
  4. * https://github.com/anncwb/vite-plugin-compression
  5. */
  6. import type { Plugin } from 'vite'
  7. import compressPlugin from 'vite-plugin-compression'
  8. export default function configCompressPlugin(
  9. compress: 'gzip' | 'brotli',
  10. deleteOriginFile = false
  11. ): Plugin | Plugin[] {
  12. const plugins: Plugin[] = []
  13. if (compress === 'gzip') {
  14. plugins.push(
  15. compressPlugin({
  16. ext: '.gz',
  17. deleteOriginFile
  18. })
  19. )
  20. }
  21. if (compress === 'brotli') {
  22. plugins.push(
  23. compressPlugin({
  24. ext: '.br',
  25. algorithm: 'brotliCompress',
  26. deleteOriginFile
  27. })
  28. )
  29. }
  30. return plugins
  31. }