ionian/packages/client/vite.config.ts
monoid 58adb46323 feat: Add BuildInfoCard component
This commit adds a new component called BuildInfoCard. The BuildInfoCard component displays information about the build, including the Git branch, Git hash, build time, and build version. It is used in the SettingPage component.

The packages/client/vite.config.ts file is modified to define environment variables for the build information. The __BUILD_TIME__, __BUILD_VERSION__, __GIT_BRANCH__, and __GIT_HASH__ variables are defined using functions that retrieve the current build time, build version, Git branch, and Git hash respectively.

This commit introduces new functionality and improves the user experience by providing build information in the application.
2024-10-13 01:40:01 +09:00

51 lines
1.1 KiB
TypeScript

import { defineConfig, loadEnv } from 'vite'
import path from 'node:path'
import react from '@vitejs/plugin-react-swc'
import { execSync } from "child_process";
function getCurrentGitHash(): string {
const gitHash = execSync("git rev-parse HEAD")
.toString()
.trim();
return gitHash;
}
function getBuildTime(): string {
return new Date().toISOString();
}
function getBuildVersion(): string {
return process.env.BUILD_VERSION ?? getCurrentGitHash();
}
function getCurrentGitBranch(): string {
const gitBranch = execSync("git rev-parse --abbrev-ref HEAD")
.toString()
.trim();
return gitBranch;
}
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), "");
return {
plugins: [react()],
define: {
__BUILD_TIME__: `"${getBuildTime()}"`,
__BUILD_VERSION__: `"${getBuildVersion()}"`,
__GIT_BRANCH__: `"${getCurrentGitBranch()}"`,
__GIT_HASH__: `"${getCurrentGitHash()}"`,
},
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
server: {
proxy: {
'/api': env.API_BASE_URL ?? 'http://localhost:8000',
}
}
}})