-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathvite.config.ts
More file actions
67 lines (61 loc) · 1.94 KB
/
vite.config.ts
File metadata and controls
67 lines (61 loc) · 1.94 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
56
57
58
59
60
61
62
63
64
65
66
67
import react from '@vitejs/plugin-react'
import { Instance } from 'prool'
import { defineConfig, loadEnv, type Plugin } from 'vite'
import mkcert from 'vite-plugin-mkcert'
import { vocs } from 'vocs/vite'
import { moderatoZoneRpcUrls } from './src/lib/private-zones.ts'
// https://vite.dev/config/
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '')
for (const key of Object.keys(env)) {
if (!(key in process.env)) process.env[key] = env[key]
}
const useHttp = process.env.CI === 'true' || process.env.VITE_USE_HTTP === 'true'
const e2eZoneProxy = env.VITE_E2E === 'true' ? getE2EZoneProxy() : undefined
return {
plugins: [vocs(), react(), ...(useHttp ? [] : [mkcert()]), tempoNode()],
server: useHttp
? {
host: 'localhost',
proxy: e2eZoneProxy,
}
: undefined,
}
})
function getE2EZoneProxy() {
return Object.fromEntries(
Object.entries(moderatoZoneRpcUrls).map(([zoneId, rpcUrl]) => {
const parsedUrl = new URL(rpcUrl)
const authorization = `Basic ${Buffer.from(
`${decodeURIComponent(parsedUrl.username)}:${decodeURIComponent(parsedUrl.password)}`,
).toString('base64')}`
parsedUrl.username = ''
parsedUrl.password = ''
return [
`/__e2e_zone_rpc/${zoneId}`,
{
changeOrigin: true,
headers: { authorization },
rewrite: () => '/',
secure: true,
target: parsedUrl.toString(),
},
]
}),
)
}
function tempoNode(): Plugin {
return {
name: 'tempo-node',
async configureServer(_server) {
if (!('VITE_TEMPO_ENV' in process.env) || process.env.VITE_TEMPO_ENV !== 'localnet') return
const instance = Instance.tempo({
dev: { blockTime: '500ms' },
port: 8545,
})
console.log('→ starting tempo node...')
await instance.start()
console.log('√ tempo node started on port 8545')
},
}
}