-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathvite.config.ts
63 lines (61 loc) · 1.96 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
import { execSync } from 'node:child_process'
import { defineConfig, normalizePath } from 'vite'
import solid from 'vite-plugin-solid'
import wisp from 'wisp-server-node'
import { viteStaticCopy } from 'vite-plugin-static-copy'
import { uvPath } from '@titaniumnetwork-dev/ultraviolet'
import { baremuxPath } from '@mercuryworkshop/bare-mux/node'
// @ts-expect-error
import { epoxyPath } from '@mercuryworkshop/epoxy-transport'
import { libcurlPath } from '@mercuryworkshop/libcurl-transport'
import path from 'node:path'
export default defineConfig({
plugins: [
solid(),
{
name: 'Wisp Server',
configureServer(server) {
server.httpServer?.on('upgrade', (req, socket, head) => {
if (req.url?.startsWith('/wisp/')) {
wisp.routeRequest(req, socket, head)
}
})
}
},
viteStaticCopy({
targets: [
{
src: [normalizePath(path.resolve(uvPath, 'uv.bundle.js')), normalizePath(path.resolve(uvPath, 'uv.handler.js')), normalizePath(path.resolve(uvPath, 'uv.client.js')), normalizePath(path.resolve(uvPath, 'uv.sw.js'))],
dest: 'coffee'
},
{
src: normalizePath(path.resolve(baremuxPath, 'worker.js')),
dest: 'bare-mux'
},
{
src: normalizePath(path.resolve(epoxyPath, 'index.mjs')),
dest: 'epoxy'
},
{
src: normalizePath(path.resolve(libcurlPath, 'index.mjs')),
dest: 'libcurl'
}
]
})
],
server: {
proxy: {
// For development purposes
'/cdn': {
target: 'https://assets.3kh0.net',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/cdn/, '')
}
}
},
define: {
__BUILD_DATE__: Date.now(),
__GIT_COMMIT__: JSON.stringify(process.env.VERCEL_GIT_COMMIT_SHA ?? process.env.CF_PAGES_COMMIT_SHA ?? execSync('git rev-parse HEAD').toString().trim()),
__PRODUCTION__: process.env.NODE_ENV === 'production'
}
})