-
Notifications
You must be signed in to change notification settings - Fork 202
Expand file tree
/
Copy pathvite.config.ts
More file actions
144 lines (137 loc) · 4.08 KB
/
Copy pathvite.config.ts
File metadata and controls
144 lines (137 loc) · 4.08 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
137
138
139
140
141
142
143
144
/// <reference types="vitest" />
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import svgr from "vite-plugin-svgr";
import path from "path";
import process from "node:process";
import { fileURLToPath } from "url";
import { readWorkspaceAppVersion } from "./scripts/app-version.mjs";
// ES 模块中获取 __dirname 的方式
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const cargoWorkspaceVersion = readWorkspaceAppVersion(__dirname);
const appVersion =
process.env.VITE_APP_VERSION?.trim() || cargoWorkspaceVersion || "unknown";
const liveProviderSmokeAllowed =
isTruthyEnv(process.env.LIME_ALLOW_LIVE_PROVIDER_SMOKE) ||
isTruthyEnv(process.env.LIME_REAL_API_TEST);
if (!process.env.VITE_APP_VERSION && cargoWorkspaceVersion) {
process.env.VITE_APP_VERSION = cargoWorkspaceVersion;
}
function isTruthyEnv(value: string | undefined): boolean {
return /^(1|true|yes|on)$/i.test(String(value || "").trim());
}
export default defineConfig(({ command, mode }) => {
const forceOptimizeDeps =
process.env.LIME_VITE_FORCE_OPTIMIZE_DEPS?.trim() === "1";
const isElectronRenderer =
process.env.LIME_ELECTRON_RENDERER?.trim() === "1" ||
process.env.VITE_DEV_SERVER_URL !== undefined;
const cacheDir = isElectronRenderer
? "node_modules/.vite-electron"
: "node_modules/.vite-web";
return {
base: command === "build" && isElectronRenderer ? "./" : undefined,
cacheDir,
define: {
"import.meta.env.VITE_APP_VERSION": JSON.stringify(appVersion),
},
plugins: [
react({
jsxRuntime: mode === "development" ? "automatic" : "automatic",
jsxImportSource: "react",
babel: {
compact: true,
},
}),
svgr(),
],
resolve: {
alias: [
{
find: "@",
replacement: path.resolve(__dirname, "./src"),
},
{
find: "@limecloud/app-server-client",
replacement: path.resolve(
__dirname,
"./packages/app-server-client/src/index.ts",
),
},
{
find: "@limecloud/agent-runtime-client/sessionGateway",
replacement: path.resolve(
__dirname,
"./packages/agent-runtime-client/src/sessionGateway.ts",
),
},
{
find: "@limecloud/agent-runtime-client",
replacement: path.resolve(
__dirname,
"./packages/agent-runtime-client/src/index.ts",
),
},
{
find: "@limecloud/agent-ui-contracts",
replacement: path.resolve(
__dirname,
"./packages/agent-ui-contracts/src/index.ts",
),
},
{
find: "@limecloud/agent-runtime-projection",
replacement: path.resolve(
__dirname,
"./packages/agent-runtime-projection/src/index.ts",
),
},
{
find: "@limecloud/agent-runtime-ui",
replacement: path.resolve(
__dirname,
"./packages/agent-runtime-ui/src/index.ts",
),
},
],
},
optimizeDeps: {
force: forceOptimizeDeps,
},
build: {
chunkSizeWarningLimit: 12000,
rollupOptions: {
onwarn(warning, defaultHandler) {
const isMixedImportWarning =
warning.message.includes("dynamically imported by") &&
warning.message.includes("also statically imported by");
if (isMixedImportWarning) {
return;
}
defaultHandler(warning);
},
},
},
clearScreen: false,
server: {
host: "127.0.0.1",
port: 1420,
strictPort: true,
watch: {
ignored: ["**/lime-rs/**"],
},
},
test: {
globals: true,
environment: "jsdom",
setupFiles: ["./scripts/setup-vitest-network-guard.ts"],
exclude: [
"**/node_modules/**",
"**/tmp/lime-pnpm-frozen-node_modules/**",
"**/dist/**",
"**/lime-rs/target/**",
...(liveProviderSmokeAllowed ? [] : ["**/*.live.test.*"]),
],
},
};
});