-
Notifications
You must be signed in to change notification settings - Fork 4
/
vite.config.ts
58 lines (56 loc) · 1.55 KB
/
vite.config.ts
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
// @ts-nocheck
import { narrowSolidPlugin } from "@merged/react-solid/plugin";
import { applyWSSHandler } from "@trpc/server/adapters/ws";
import { sveltekit } from "@sveltejs/kit/vite";
import type { UserConfig } from "vite";
import { WebSocketServer } from "ws";
import { resolve } from "path";
import { parse } from "url";
const config = {
plugins: [
sveltekit(),
narrowSolidPlugin({
include: /\/src\/demo\/frameworks\/solid/,
hot: false,
}),
{
name: "vite-trpc-ws",
async configureServer(server) {
const { router } = await import("./src/demo/server");
const wss = new WebSocketServer({ noServer: true });
server.httpServer?.on("upgrade", (request, socket, head) => {
const { pathname } = parse(request.url);
if (pathname === "/trpc") {
wss.handleUpgrade(request, socket, head, (ws) => {
wss.emit("connection", ws, request);
});
}
});
applyWSSHandler({ wss, router });
},
},
],
resolve: {
alias: [
{
find: "crstore/runtime",
customResolver: (_0: any, _1: any, { ssr }: { ssr?: boolean }) =>
ssr ? resolve("./runtime/node.js") : resolve("./runtime/browser.js"),
} as any,
],
},
build: {
target: "es2020",
rollupOptions: { external: ["path", "url"] },
},
optimizeDeps: {
esbuildOptions: {
target: "es2020",
},
},
server: {
fs: { allow: ["runtime"] },
},
test: { env: { SSR: "" } },
} satisfies UserConfig;
export default config;