Files
ttstd-infinite-canvas/web/vite.config.ts

83 lines
3.4 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 { 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,
},
],
},
},
},
},
});