Repository navigation
Expand file tree
/
Copy pathvite.config.ts
More file actions
136 lines (128 loc) · 3.75 KB
/
Copy pathvite.config.ts
File metadata and controls
136 lines (128 loc) · 3.75 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import path from "node:path";
import babel from "@rolldown/plugin-babel";
import tailwindcss from "@tailwindcss/vite";
import react, { reactCompilerPreset } from "@vitejs/plugin-react";
import { visualizer } from "rollup-plugin-visualizer";
import { defineConfig, type PluginOption } from "vite";
const platform = process.env.TAURI_ENV_PLATFORM;
console.debug("platform : ", platform);
const target = (() => {
if (platform === "windows") return "chrome139";
if (platform === "darwin") return "safari16";
return "es2020";
})();
const reactDevTools = (): PluginOption => {
return {
name: "react-devtools",
apply: "serve",
transformIndexHtml(html) {
return {
html,
tags: [
{
tag: "script",
attrs: {
src: "http://localhost:8097",
},
injectTo: "head",
},
],
};
},
};
};
const e2eEntry = (): PluginOption => {
return {
name: "hardware-visualizer-e2e-entry",
apply: "serve",
transformIndexHtml(html) {
return html.replace("/src/main.tsx", "/src/main.e2e.tsx");
},
};
};
// https://vitejs.dev/config/
export default defineConfig(async ({ mode }) => ({
plugins: [
react(),
babel({ presets: [reactCompilerPreset()] }),
tailwindcss(),
mode === "react-devtools" && reactDevTools(),
mode === "e2e" && e2eEntry(),
],
build: {
target: target,
rolldownOptions: {
output: {
codeSplitting: {
groups: [
{
name: "vendor-chart",
test: /[\\/]node_modules[\\/](recharts|d3-[^\\/]+|victory-vendor|es-toolkit)[\\/]/,
},
{
name: "vendor-react",
test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/,
},
{
name: "vendor-i18n",
test: /[\\/]node_modules[\\/](i18next|react-i18next)[\\/]/,
},
{ name: "vendor-state", test: /[\\/]node_modules[\\/]jotai[\\/]/ },
{ name: "vendor-dnd", test: /[\\/]node_modules[\\/]@dnd-kit[\\/]/ },
{
name: "vendor-radix",
test: /[\\/]node_modules[\\/]@radix-ui[\\/]/,
},
{
name: "vendor-tauri",
test: /[\\/]node_modules[\\/]@tauri-apps[\\/]/,
},
],
},
},
plugins: [
// Enable `npx vite build --mode analyze`
mode === "analyze" &&
visualizer({
open: true,
gzipSize: true,
brotliSize: true,
}),
],
},
},
// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
//
// 1. prevent vite from obscuring rust errors
clearScreen: false,
// 2. tauri expects a fixed port, fail if that port is not available
server: {
port: 1520,
strictPort: true,
watch: {
// 3. tell vite to ignore Rust sources, build artifacts, and
// generated trees that churn during test runs - .claude holds
// AI-agent worktrees whose coverage output was observed
// triggering full page reloads into a live dev session, and
// the repo's own vitest coverage / Playwright test-results
// reproduce the same pattern at the repo root.
ignored: [
"**/src-tauri/**",
"**/target/**",
"**/.claude/**",
"**/coverage/**",
"**/test-results/**",
],
},
},
resolve: {
alias: {
"@": path.resolve(import.meta.dirname, "src"),
},
},
optimizeDeps: {
// Pre-bundle the Tauri mock module only in E2E mode so the regular app
// entry path stays independent from the web/mock harness.
include: mode === "e2e" ? ["@tauri-apps/api/mocks"] : [],
},
}));