-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
80 lines (79 loc) · 2.34 KB
/
vite.config.ts
File metadata and controls
80 lines (79 loc) · 2.34 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
68
69
70
71
72
73
74
75
76
77
78
79
80
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import compression from 'vite-plugin-compression'
import { visualizer } from 'rollup-plugin-visualizer'
import path from 'node:path'
// https://vite.dev/config/
export default defineConfig({
plugins: [
react(),
compression({
algorithm: 'gzip',
ext: '.gz',
}),
visualizer({
filename: './dist/stats.html',
open: false,
gzipSize: true,
brotliSize: true,
}),
],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
server: {
proxy: {
'/api/bugzilla': {
target: 'https://bugzilla.mozilla.org/rest',
changeOrigin: true,
secure: true,
followRedirects: true,
rewrite: (path) => path.replace(/^\/api\/bugzilla/, ''),
// Handle OPTIONS preflight requests without proxying
bypass(req, res) {
if (req.method === 'OPTIONS') {
res.writeHead(204, {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type, X-BUGZILLA-API-KEY',
'Access-Control-Max-Age': '86400',
})
res.end()
return false // Don't proxy this request
}
},
configure: (proxy) => {
proxy.on('proxyReq', (proxyReq, req) => {
// Forward the API key header
const apiKey = req.headers['x-bugzilla-api-key']
if (apiKey) {
proxyReq.setHeader('X-BUGZILLA-API-KEY', apiKey as string)
}
})
proxy.on('proxyRes', (_proxyRes, _req, res) => {
// Add CORS headers to proxied responses
res.setHeader('Access-Control-Allow-Origin', '*')
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS')
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, X-BUGZILLA-API-KEY')
})
},
},
},
},
build: {
target: 'esnext',
minify: 'esbuild',
sourcemap: false,
rollupOptions: {
output: {
manualChunks: {
'react-vendor': ['react', 'react-dom'],
'animation-vendor': ['framer-motion'],
'store-vendor': ['zustand'],
},
},
},
},
})