forked from Nam3IsTak3n/Metallic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
71 lines (67 loc) · 2 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
59
60
61
62
63
64
65
66
67
68
69
70
71
import { defineConfig } from 'vite';
import preact from '@preact/preset-vite';
import { ViteMinifyPlugin } from 'vite-plugin-minify';
import { createBareServer } from '@tomphttp/bare-server-node';
import wisp from "wisp-server-node";
//@ts-ignore
import { epoxyPath } from "@mercuryworkshop/epoxy-transport";
import { viteStaticCopy } from "vite-plugin-static-copy";
//@ts-ignore
import { generateFile } from './src/util/generateFileVite';
//@ts-ignore
import { generateThemes } from './src/util/generateThemes';
import themes from './src/themes.json';
// https://vitejs.dev/config/
export default defineConfig({
build: {
outDir: "build",
},
plugins: [
viteStaticCopy({
targets: [
{
src: `${epoxyPath}/**/*`.replace(/\\/g, "/"),
dest: "epoxy",
overwrite: false
}
]
}),
{
name: "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 (req.url && req.url.endsWith("/wisp/")) {
//@ts-ignore
wisp.routeRequest(req, socket, head);
} else if (bare.shouldRoute(req)) {
bare.routeUpgrade(req, socket, head);
} else {
for (const upgrader of upgraders) {
//@ts-ignore
upgrader(req, socket, head);
}
}
});
},
},
generateFile([{
contentType: 'text/css',
output: 'themes.css',
data: generateThemes(themes)
}]),
ViteMinifyPlugin(),
preact()
],
})