forked from kubestellar/ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
86 lines (74 loc) · 2.75 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { visualizer } from "rollup-plugin-visualizer";
import EnvironmentPlugin from 'vite-plugin-environment'
import { execSync } from 'child_process';
// DOCS: https://www.npmjs.com/package/rollup-plugin-visualizer
// https://vitejs.dev/config/
// Utility function to extract the current git commit hash
// Provides a short 7-character version of the full commit hash
const getGitCommitHash = () => {
try {
return execSync('git rev-parse HEAD').toString().trim().slice(0, 7);
} catch (error) {
console.error('Failed to retrieve git commit hash:', error);
return 'unknown';
}
};
// Vite configuration for KubeStellar UI project
// Includes React plugin, environment variable management, and bundle visualization
export default defineConfig({
plugins: [
// React framework integration
react(),
// Environment variable management
// Enables access to base URL and git commit hash across the application
EnvironmentPlugin({
VITE_BASE_URL: process.env.VITE_BASE_URL,
VITE_GIT_COMMIT_HASH: getGitCommitHash(),
}),
// Bundle size and composition visualization
// Helps in understanding application's build characteristics
visualizer({
filename: "bundle-stats.html", // Output file for the analysis
open: true, // Automatically open the file in the browser if true
gzipSize: true, // Show gzip sizes
brotliSize: true, // Show brotli sizes
// template: 'network', // sunburst, treemap, network, raw-data, list, flamegraph
}),
],
// Global compile-time constants and environment variable definitions
// Ensures commit hash is available during build and runtime
define: {
'import.meta.env.VITE_GIT_COMMIT_HASH': JSON.stringify(getGitCommitHash()),
},
build: {
rollupOptions: {
output: {
manualChunks: {
// Core vendor dependencies
'vendor-react': ['react', 'react-dom', 'react-router-dom'],
// MUI core and icons in separate chunks
'vendor-mui-core': ['@mui/material'],
'vendor-mui-icons': ['@mui/icons-material'],
'vendor-mui-tree': ['@mui/x-tree-view'],
// Feature-specific chunks
'charts': ['recharts'],
'editor': ['@monaco-editor/react'],
'terminal': ['xterm', 'xterm-addon-fit'],
// Utility libraries
'utils': ['axios', 'js-yaml', 'nanoid'],
},
}
},
},
// Add preload directives
experimental: {
renderBuiltUrl(filename: string, { hostType }: { hostType: 'js' | 'css' | 'html' }) {
if (hostType === 'html') {
return { relative: true, preload: true };
}
return { relative: true };
}
},
})