Repository navigation
Expand file tree
/
Copy pathvite.config.ts
More file actions
106 lines (101 loc) · 2.7 KB
/
Copy pathvite.config.ts
File metadata and controls
106 lines (101 loc) · 2.7 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
import { URL, fileURLToPath } from "node:url"
import { devtools } from "@tanstack/devtools-vite"
import { tanstackStart } from "@tanstack/react-start/plugin/vite"
import { nitro } from "nitro/vite"
import { defineConfig } from "vite"
import pkg from "./package.json" with { type: "json" }
import react from "@vitejs/plugin-react"
import { attachSignalingRoutes } from "./src/server/signalling/server.ts"
import { printWelcome } from "./src/utils/welcome.ts"
import fs from "node:fs"
import path from "node:path"
interface ViteServerConfig {
host: string
frontendPort: number
}
function getViteServerConfig(): ViteServerConfig {
const defaultConfig: ViteServerConfig = {
host: "0.0.0.0",
frontendPort: 3000,
}
try {
const configPath = path.resolve(
import.meta.dirname,
"src/server-config.json",
)
if (fs.existsSync(configPath)) {
const raw: unknown = JSON.parse(fs.readFileSync(configPath, "utf-8"))
if (raw && typeof raw === "object" && !Array.isArray(raw)) {
const obj = raw as Record<string, unknown>
const host =
typeof obj.host === "string" ? obj.host : defaultConfig.host
const frontendPort =
typeof obj.frontendPort === "number" &&
Number.isInteger(obj.frontendPort) &&
obj.frontendPort >= 1 &&
obj.frontendPort <= 65535
? obj.frontendPort
: defaultConfig.frontendPort
return { host, frontendPort }
}
}
} catch {}
return defaultConfig
}
const serverConfig = getViteServerConfig()
// biome-ignore lint/suspicious/noExplicitAny: Vite server instance
const wireServer = (server: any) => {
attachSignalingRoutes(server)
server.httpServer?.once("listening", () => {
const addr = server.httpServer?.address()
const port =
addr && typeof addr === "object" ? addr.port : serverConfig.frontendPort
printWelcome(port)
})
}
const config = defineConfig({
define: {
__APP_VERSION__: JSON.stringify(pkg.version),
__FRONTEND_PORT__: JSON.stringify(serverConfig.frontendPort),
},
base: "/",
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
},
},
plugins: [
{
name: "rein-server",
configureServer: wireServer,
configurePreviewServer: wireServer,
},
devtools(),
nitro({
plugins: ["./src/server/nitro-plugin"],
rollupConfig: {
external: ["koffi", "x11"],
},
}),
tanstackStart(),
react({
babel: {
plugins: [["babel-plugin-react-compiler", {}]],
},
}),
],
ssr: {
noExternal: ["tailwindcss", "@tailwindcss/postcss"],
},
server: {
host: serverConfig.host === "0.0.0.0" ? true : serverConfig.host,
port: serverConfig.frontendPort,
watch: {
ignored: ["**/server-config.json", "**/src/server-config.json"],
},
},
build: {
rollupOptions: {},
},
})
export default config