-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathvite.config.ts
52 lines (45 loc) · 1.8 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
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()),
}
})