-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathvite.config.ts
More file actions
84 lines (81 loc) · 2.5 KB
/
vite.config.ts
File metadata and controls
84 lines (81 loc) · 2.5 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
81
82
83
84
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import tailwindcss from '@tailwindcss/vite';
import { tanstackRouter } from '@tanstack/router-plugin/vite';
import { visualizer } from 'rollup-plugin-visualizer';
import path from 'path';
import { generateHeadPlugin } from './vite-plugins/generate-head-plugin';
const BACKENDS: Record<string, string> = {
local: 'http://localhost:8080',
production: 'https://lab.ethpandaops.io:443',
};
const backendKey = process.env.BACKEND ?? 'local';
const backendTarget = BACKENDS[backendKey] ?? backendKey;
// https://vite.dev/config/
export default defineConfig({
base: '/',
define: {
'import.meta.env.VITE_BASE_TITLE': JSON.stringify('The Lab by ethPandaOps'),
'import.meta.env.VITE_BASE_URL': JSON.stringify('https://lab.ethpandaops.io'),
},
plugins: [
tanstackRouter({
routesDirectory: './src/routes',
generatedRouteTree: './src/routeTree.gen.ts',
autoCodeSplitting: true,
quoteStyle: 'single',
}),
tailwindcss(),
react(),
visualizer({
open: false,
gzipSize: true,
brotliSize: true,
filename: 'build/stats.html',
}),
generateHeadPlugin(),
],
server: {
proxy: {
'/api': {
target: backendTarget,
changeOrigin: true,
secure: backendTarget.startsWith('https'),
},
},
},
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
conditions: ['import', 'module', 'browser', 'default'],
},
build: {
outDir: 'dist',
commonjsOptions: {
transformMixedEsModules: true, // Handle packages with mixed ESM/CommonJS
},
rollupOptions: {
output: {
// Generate fresh random hashes on every build to bust cache completely
chunkFileNames: () => {
const randomHash = Math.random().toString(36).substring(2, 10);
return `assets/[name]-${randomHash}.js`;
},
entryFileNames: () => {
const randomHash = Math.random().toString(36).substring(2, 10);
return `assets/[name]-${randomHash}.js`;
},
assetFileNames: assetInfo => {
// Keep fonts stable for caching (they never change)
if (assetInfo.name?.match(/\.(woff2?|ttf|eot|otf)$/)) {
return 'assets/[name]-[hash].[ext]';
}
// Random hash for everything else
const randomHash = Math.random().toString(36).substring(2, 10);
return `assets/[name]-${randomHash}.[ext]`;
},
},
},
},
});