ionian/packages/client/vite.config.ts

51 lines
1.1 KiB
TypeScript
Raw Permalink Normal View History

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',
}
}
}})