-
Notifications
You must be signed in to change notification settings - Fork 145
/
vite.config.ts
45 lines (41 loc) · 1.49 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
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import svgr from "vite-plugin-svgr";
import pluginRewriteAll from "vite-plugin-rewrite-all";
import { createBareServer } from "@tomphttp/bare-server-node";
import { ViteMinifyPlugin } from "vite-plugin-minify";
export default defineConfig({
build: {
outDir: "build",
},
appType: "mpa",
plugins: [
{
name: "bare server",
configureServer(server) {
const bare = createBareServer("/bare/");
server.middlewares.use((req, res, next) => {
if (bare.shouldRoute(req)) bare.routeRequest(req, res);
else next();
});
const upgraders = server.httpServer.listeners(
"upgrade"
) as Parameters<(typeof server)["httpServer"]["on"]>[1][];
// remover other listeners
for (const upgrader of upgraders)
server.httpServer.off("upgrade", upgrader);
server.httpServer.on("upgrade", (req, socket, head) => {
if (bare.shouldRoute(req))
bare.routeUpgrade(req, socket, head);
else
for (const upgrader of upgraders)
upgrader(req, socket, head);
});
},
},
react(),
svgr(),
pluginRewriteAll(),
ViteMinifyPlugin(),
],
});