_compression.ts 594 B

123456789101112131415161718192021222324252627
  1. import compression from "vite-plugin-compression"
  2. export default function createCompression(env: Record<string, string>) {
  3. const { VITE_BUILD_COMPRESS } = env
  4. const plugin = []
  5. if (VITE_BUILD_COMPRESS != "") {
  6. const compressList = VITE_BUILD_COMPRESS.split(",")
  7. if (compressList.includes("gzip")) {
  8. plugin.push(
  9. compression({
  10. ext: ".gz",
  11. deleteOriginFile: false
  12. })
  13. )
  14. }
  15. if (compressList.includes("brotli")) {
  16. plugin.push(
  17. compression({
  18. ext: ".br",
  19. algorithm: "brotliCompress",
  20. deleteOriginFile: false
  21. })
  22. )
  23. }
  24. }
  25. return plugin
  26. }