2026-06-10 14:06:16 +08:00
|
|
|
import react from "@vitejs/plugin-react";
|
|
|
|
|
import { compression } from "vite-plugin-compression2";
|
|
|
|
|
import { defineConfig } from "vite";
|
|
|
|
|
|
2026-06-15 10:24:31 +08:00
|
|
|
export default defineConfig(({ command }) => {
|
|
|
|
|
// dev 模式下默认把 /api 代理到线上电商后端,本地 `npm run dev` 即可直接登录/生成。
|
|
|
|
|
// 想连本地或 SSH 隧道的后端时,用环境变量覆盖:
|
|
|
|
|
// $env:OMNIAI_DEV_API_TARGET="http://127.0.0.1:3601"; npm run dev
|
|
|
|
|
// 仅 dev 代理用途,不会打进生产构建产物。
|
|
|
|
|
const devApiTarget =
|
|
|
|
|
process.env.OMNIAI_DEV_API_TARGET?.trim() ||
|
|
|
|
|
(command === "serve" ? "https://omniai.com.cn" : "");
|
2026-06-12 17:25:30 +08:00
|
|
|
const apiProxy = devApiTarget
|
|
|
|
|
? {
|
|
|
|
|
"/api": {
|
|
|
|
|
target: devApiTarget,
|
|
|
|
|
changeOrigin: true,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
: undefined;
|
2026-06-12 11:12:55 +08:00
|
|
|
|
|
|
|
|
return {
|
2026-06-10 14:06:16 +08:00
|
|
|
plugins: [
|
|
|
|
|
react(),
|
|
|
|
|
compression({ algorithms: ["gzip", "brotliCompress"], threshold: 1024 }),
|
|
|
|
|
],
|
|
|
|
|
server: {
|
|
|
|
|
port: 5173,
|
|
|
|
|
host: "127.0.0.1",
|
2026-06-12 17:25:30 +08:00
|
|
|
...(apiProxy ? { proxy: apiProxy } : {}),
|
2026-06-10 14:06:16 +08:00
|
|
|
},
|
|
|
|
|
preview: {
|
|
|
|
|
port: 4174,
|
|
|
|
|
host: "127.0.0.1",
|
|
|
|
|
},
|
2026-06-15 10:24:31 +08:00
|
|
|
...(command === "build" ? { esbuild: { drop: ["console", "debugger"] } } : {}),
|
2026-06-10 14:06:16 +08:00
|
|
|
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";
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2026-06-12 11:12:55 +08:00
|
|
|
};
|
|
|
|
|
});
|