PMFlow/frontend/vite.config.ts

131 lines
4.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import path from "path";
import react from "@vitejs/plugin-react";
import { defineConfig, loadEnv } from "vite";
const watchIgnored = [
"**/node_modules/**",
"**/dist/**",
"**/output/**",
"**/.playwright-cli/**",
"**/playwright-report/**",
"**/test-results/**",
];
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), "");
// 本地默认优先对齐 Docker 开发栈:backend 暴露在 8001 -> 容器内 8000。
// 若开发者直跑后端,可通过 VITE_DEV_API_PROXY_TARGET 覆盖回 8000。
const proxyTarget = env.VITE_DEV_API_PROXY_TARGET || "http://127.0.0.1:8001";
const usePolling = String(env.CHOKIDAR_USEPOLLING || "false").toLowerCase() === "true";
return {
plugins: [react()],
build: {
rollupOptions: {
output: {
manualChunks(id) {
const normalizedId = id.split(path.sep).join("/");
if (
normalizedId.includes("/node_modules/react/") ||
normalizedId.includes("/node_modules/react-dom/") ||
normalizedId.includes("/node_modules/react-router-dom/") ||
normalizedId.includes("/node_modules/@remix-run/router/")
) {
return "framework";
}
if (
normalizedId.includes("/node_modules/@tanstack/react-query/") ||
normalizedId.includes("/node_modules/zustand/") ||
normalizedId.includes("/node_modules/axios/")
) {
return "state-query";
}
if (normalizedId.includes("/node_modules/@radix-ui/")) {
return "ui-radix";
}
if (normalizedId.includes("/node_modules/lucide-react/")) {
return "icons";
}
if (normalizedId.includes("/node_modules/recharts/")) {
return "charts";
}
if (
normalizedId.includes("/node_modules/react-markdown/") ||
normalizedId.includes("/node_modules/remark-gfm/") ||
normalizedId.includes("/node_modules/remark-breaks/")
) {
return "markdown";
}
if (
normalizedId.includes("/src/pages/ai-steward/") ||
normalizedId.includes("/src/components/ai-steward/")
) {
return "ai-steward";
}
if (
normalizedId.includes("/src/pages/project-board/") ||
normalizedId.includes("/src/pages/charter-detail/") ||
normalizedId.includes("/src/components/sstc/") ||
normalizedId.includes("/src/components/project-control/") ||
normalizedId.includes("/src/components/model-capability/") ||
normalizedId.includes("/src/components/budget/")
) {
return "sstc";
}
if (
normalizedId.includes("/src/pages/ai-config/") ||
normalizedId.includes("/src/pages/query-route-governance/") ||
normalizedId.includes("/src/pages/semantic-facts-board/") ||
normalizedId.includes("/src/pages/model-routing-config/") ||
normalizedId.includes("/src/pages/knowledge-graph-context-board/")
) {
return "governance";
}
return undefined;
},
},
},
},
test: {
environment: "jsdom",
setupFiles: "./vitest.setup.ts",
globals: false,
},
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
server: {
port: 5174,
allowedHosts: true,
watch: {
ignored: watchIgnored,
...(usePolling
? {
usePolling: true,
interval: 250,
}
: {}),
},
proxy: {
"/api": {
target: proxyTarget,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ""),
},
},
},
};
});