compression.js 726B

12345678910111213141516171819202122232425262728
  1. import compression from "vite-plugin-compression";
  2. export default function createCompression(env) {
  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. // http://doc.ruoyi.vip/ruoyi-vue/other/faq.html#使用gzip解压缩静态文件
  9. plugin.push(
  10. compression({
  11. ext: ".gz",
  12. deleteOriginFile: false
  13. })
  14. );
  15. }
  16. if (compressList.includes("brotli")) {
  17. plugin.push(
  18. compression({
  19. ext: ".br",
  20. algorithm: "brotliCompress",
  21. deleteOriginFile: false
  22. })
  23. );
  24. }
  25. }
  26. return plugin;
  27. }