You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
906 B

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