Repository navigation
Expand file tree
/
Copy pathvite.config.ts
More file actions
90 lines (86 loc) · 2.47 KB
/
Copy pathvite.config.ts
File metadata and controls
90 lines (86 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import tailwindcss from "@tailwindcss/vite";
import path from "node:path";
import { fileURLToPath } from "node:url";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const host = process.env.TAURI_DEV_HOST;
const chunkMaxSize = 450 * 1024;
function nodeModulePattern(packageNames: string[]) {
return new RegExp(
String.raw`[\\/]node_modules[\\/](?:\.pnpm[\\/][^\\/]+[\\/]node_modules[\\/])?(?:${packageNames.join(
"|",
)})(?:[\\/]|$)`,
);
}
// https://vite.dev/config/
export default defineConfig(async () => ({
plugins: [react(), tailwindcss()],
resolve: {
alias: { "@": path.resolve(__dirname, "./src") },
},
build: {
// 仅放宽 Shiki 的单语言/wasm 异步资源告警;应用入口与页面 chunk 仍需低于默认 500 kB。
chunkSizeWarningLimit: 850,
rolldownOptions: {
output: {
codeSplitting: {
// CodeMirror / Markdown / Recharts 依赖图存在循环引用,强制拆 vendor chunk 会导致 Tauri 生产包初始化顺序错误。
groups: [
{
name: "react-vendor",
test: nodeModulePattern(["react", "react-dom", "scheduler"]),
priority: 60,
maxSize: chunkMaxSize,
},
{
name: "diff-viewer-vendor",
test: nodeModulePattern([
"@pierre",
"@shikijs",
"diff",
"hast-util-to-html",
"lru_map",
"shiki",
]),
priority: 45,
maxSize: chunkMaxSize,
},
{
name: "ui-vendor",
test: nodeModulePattern([
"class-variance-authority",
"cmdk",
"lucide-react",
"radix-ui",
"react-day-picker",
"sonner",
"tailwind-merge",
]),
priority: 30,
maxSize: chunkMaxSize,
},
],
},
},
},
},
// 避免 Vite 清屏遮挡 Rust 错误
clearScreen: false,
server: {
port: 17420,
strictPort: true,
host: host || false,
hmr: host
? {
protocol: "ws",
host,
port: 17421,
}
: undefined,
watch: {
// 避免前端 dev server 监听 Rust 目录
ignored: ["**/src-tauri/**"],
},
},
}));