-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
46 lines (43 loc) · 1.18 KB
/
Copy pathvite.config.ts
File metadata and controls
46 lines (43 loc) · 1.18 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
import path from "node:path";
import { defineConfig, loadEnv } from "vite";
import react from "@vitejs/plugin-react";
import tailwindcss from "@tailwindcss/vite";
function parsePort(value: string | undefined, fallback: number): number {
if (!value) return fallback;
const parsed = Number(value);
return Number.isInteger(parsed) && parsed > 0 && parsed <= 65535
? parsed
: fallback;
}
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), "");
const clientPort = parsePort(env.VITE_DEV_SERVER_PORT, 4500);
const apiPort = parsePort(env.VITE_API_PORT ?? env.API_PORT ?? env.PORT, 3100);
const apiTarget = `http://localhost:${apiPort}`;
return {
plugins: [react(), tailwindcss()],
root: "client",
envDir: process.cwd(),
resolve: {
alias: {
"@": path.resolve(__dirname, "client/src"),
},
},
server: {
host: "0.0.0.0",
allowedHosts: true,
port: clientPort,
proxy: {
"/api": apiTarget,
"/ws/terminal": {
target: apiTarget,
ws: true,
changeOrigin: true,
},
},
},
build: {
outDir: "../dist/client",
},
};
});