-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
70 lines (67 loc) · 2.1 KB
/
Copy pathvite.config.ts
File metadata and controls
70 lines (67 loc) · 2.1 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
import tailwindcss from '@tailwindcss/vite';
import react from '@vitejs/plugin-react';
import path from 'path';
import {defineConfig, loadEnv} from 'vite';
const apiMockPlugin = () => {
let totalFilesCompressed = 0;
let totalDataSaved = 0;
return {
name: 'api-mock',
configureServer(server: any) {
server.middlewares.use((req: any, res: any, next: any) => {
if (req.url === '/api/health') {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({ status: 'ok' }));
return;
}
if (req.url === '/api/stats') {
if (req.method === 'GET') {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({ totalFilesCompressed, totalDataSaved }));
return;
}
if (req.method === 'POST') {
let body = '';
req.on('data', (chunk: any) => { body += chunk.toString(); });
req.on('end', () => {
try {
const data = JSON.parse(body);
totalFilesCompressed += data.filesCount || 0;
totalDataSaved += data.bytesSaved || 0;
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({ success: true }));
} catch (e) {
res.statusCode = 500;
res.end(JSON.stringify({ error: 'Invalid JSON' }));
}
});
return;
}
}
next();
});
}
};
};
export default defineConfig(({mode}) => {
const env = loadEnv(mode, '.', '');
return {
plugins: [react(), tailwindcss(), apiMockPlugin()],
define: {
'process.env.GEMINI_API_KEY': JSON.stringify(env.GEMINI_API_KEY),
},
resolve: {
alias: {
'@': path.resolve(__dirname, '.'),
},
},
server: {
// HMR is disabled in AI Studio via DISABLE_HMR env var.
hmr: process.env.DISABLE_HMR !== 'true',
headers: {
'Cross-Origin-Opener-Policy': 'same-origin',
'Cross-Origin-Embedder-Policy': 'require-corp',
},
},
};
});