import react from "@vitejs/plugin-react";
import { compression } from "vite-plugin-compression2";
import { defineConfig } from "vite";

export default defineConfig(() => ({
    plugins: [
      react(),
      compression({ algorithms: ["gzip", "brotliCompress"], threshold: 1024 }),
    ],
    server: {
      port: 5173,
      host: "127.0.0.1",
      proxy: {
        "/api": {
          target: "https://omniai.net.cn",
          changeOrigin: true,
        },
      },
    },
    preview: {
      port: 4174,
      host: "127.0.0.1",
    },
    esbuild: {
      drop: ["console", "debugger"],
    },
    build: {
      sourcemap: false,
      rollupOptions: {
        output: {
          manualChunks(id: string) {
            if (id.includes("node_modules/react") || id.includes("node_modules/react-dom") || id.includes("node_modules/scheduler")) {
              return "vendor-react";
            }
            if (id.includes("node_modules/@ant-design") || id.includes("node_modules/antd") || id.includes("node_modules/rc-")) {
              return "vendor-antd";
            }
            if (id.includes("node_modules/@xyflow")) {
              return "vendor-xyflow";
            }
          },
        },
      },
    },
  }));
