Files
ttstd-infinite-canvas/web/vite.config.ts
T
tongtong 3c25511f47
Publish container images / Quality checks (push) Has been cancelled
Publish container images / Resolve build version (push) Has been cancelled
Publish container images / Build open-ai-canvas-backend (amd64) (push) Has been cancelled
Publish container images / Build open-ai-canvas-backend (arm64) (push) Has been cancelled
Publish container images / Build open-ai-canvas-web (multi) (push) Has been cancelled
Publish container images / Publish open-ai-canvas-backend manifest (push) Has been cancelled
Publish container images / Publish open-ai-canvas-web manifest (push) Has been cancelled
Publish container images / Publish release assets (push) Has been cancelled
build(ports): 本地开发改用 7380/7381 避开端口冲突
2026-09-21 14:54:20 +08:00

83 lines
3.4 KiB
TypeScript

import { dirname, resolve } from "node:path";
import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";
const webDir = dirname(fileURLToPath(import.meta.url));
const appVersion = process.env.CANVAS_BUILD_VERSION?.trim() || readFileSync(resolve(webDir, "../VERSION"), "utf8").trim();
const appChangelog = readFileSync(resolve(webDir, "../CHANGELOG.md"), "utf8");
// 本项目本地开发端口:前端 7380、后端 7381(见 AGENTS.md「本项目附加约定」)。
// 避开上游默认的 3000 / 8080,以便与 infinite-canvas、open-ai-canvas 等同机工程并存。
const apiProxyTarget = process.env.VITE_API_PROXY_TARGET?.trim() || "http://127.0.0.1:7381";
export default defineConfig({
plugins: [react()],
define: {
__APP_VERSION__: JSON.stringify(appVersion),
__APP_CHANGELOG__: JSON.stringify(appChangelog),
"import.meta.env.VITE_APP_VERSION": JSON.stringify(appVersion),
},
server: {
proxy: {
"/api": {
target: apiProxyTarget,
changeOrigin: true,
xfwd: true,
},
"/oauth/linuxdo/callback": {
target: apiProxyTarget,
changeOrigin: true,
xfwd: true,
},
},
},
resolve: {
alias: {
"@": resolve(webDir, "src"),
},
},
build: {
rolldownOptions: {
output: {
strictExecutionOrder: true,
codeSplitting: {
// Keep route-level lazy imports isolated. Recursively merging dependencies
// pulls unrelated pages into the initial modulepreload graph.
includeDependenciesRecursively: false,
minSize: 40 * 1024,
groups: [
{
// Shared interop helpers must not be emitted into a route entry:
// AntD would import that entry back and execute its bootstrap early.
name: "vendor-babel-runtime",
minSize: 0,
test: /node_modules[\\/]@babel[\\/]runtime[\\/]/,
priority: 40,
},
{
name: "vendor-react",
test: /node_modules[\\/](?:react(?:-dom|-router|-router-dom)?|scheduler|zustand|use-sync-external-store|@tanstack[\\/](?:query-core|react-query))[\\/]/,
priority: 30,
},
{
name: "vendor-icons",
test: /node_modules[\\/](?:lucide-react|@ant-design[\\/]icons)[\\/]/,
priority: 20,
entriesAware: true,
entriesAwareMergeThreshold: 48 * 1024,
},
{
name: "vendor-antd",
test: /node_modules[\\/](?:antd|@ant-design|@rc-component|rc-[^\\/]+|dayjs)[\\/]/,
priority: 10,
entriesAware: true,
entriesAwareMergeThreshold: 80 * 1024,
},
],
},
},
},
},
});