Repository navigation
Expand file tree
/
Copy pathvite.config.ts
More file actions
55 lines (48 loc) · 1.53 KB
/
Copy pathvite.config.ts
File metadata and controls
55 lines (48 loc) · 1.53 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
import { defineConfig, type Plugin } from "vite";
import { devtools } from "@tanstack/devtools-vite";
import { tanstackStart } from "@tanstack/react-start/plugin/vite";
import viteReact from "@vitejs/plugin-react";
import tailwindcss from "@tailwindcss/vite";
import { nitro } from "nitro/vite";
import { randomBytes } from "node:crypto";
const PORT = 3000;
/**
* Dev only: generate the session token before the server starts and print the
* URL to open, since every request without the token is rejected.
*/
function loopSession(): Plugin {
return {
name: "loop-session",
apply: "serve",
enforce: "pre",
// Runs before Nitro starts its dev worker, which copies process.env
config() {
process.env.LOOP_SESSION_TOKEN ||= randomBytes(32).toString("base64url");
process.env.LOOP_PORT = String(PORT);
},
configureServer(server) {
server.httpServer?.once("listening", () => {
const url = `http://127.0.0.1:${process.env.LOOP_PORT}/?token=${process.env.LOOP_SESSION_TOKEN}`;
setTimeout(() => server.config.logger.info(`\n Open Loop: ${url}\n`), 100);
});
},
};
}
const config = defineConfig({
resolve: { tsconfigPaths: true },
server: {
// Loop is localhost-only; the request guard expects exactly this host and port
host: "127.0.0.1",
port: PORT,
strictPort: true,
},
plugins: [
loopSession(),
devtools(),
nitro({ rollupConfig: { external: [/^@sentry\//] } }),
tailwindcss(),
tanstackStart(),
viteReact(),
],
});
export default config;