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.

39 lines
978 B

5 months ago
5 months ago
  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. // 如果compress为undefined或空字符串,返回空数组
  11. if (!compress || compress === 'none') {
  12. return []
  13. }
  14. const compressList = compress.split(',')
  15. const plugins = []
  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. }