import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; import path from 'path'; import { execSync } from 'child_process'; import fs from 'fs'; // Get version from environment, git tag, or package.json function getVersion(): string { // 1. Environment variable (set by GitHub Actions) if (process.env.VERSION) { return process.env.VERSION; } // 2. Try git tag try { const gitTag = execSync('git describe --tags --exact-match 2>/dev/null || git describe --tags 2>/dev/null || echo ""', { encoding: 'utf8' }).trim(); if (gitTag) { return gitTag; } } catch { // Git not available or no tags } // 3. Fall back to package.json version try { const pkg = JSON.parse( fs.readFileSync(path.resolve(import.meta.dirname, 'package.json'), 'utf8') ); if (pkg.version && pkg.version !== '0.0.0') { return pkg.version; } } catch { // package.json not readable } return 'dev'; } // https://vitejs.dev/config/ export default defineConfig(({ command }) => ({ base: command === 'build' ? '/management-assets/' : '/', plugins: [react()], define: { __APP_VERSION__: JSON.stringify(getVersion()) }, resolve: { alias: { '@': path.resolve(import.meta.dirname, './src') } }, server: { host: '127.0.0.1', proxy: { '/v0': { target: 'http://127.0.0.1:8317', changeOrigin: true } } }, build: { target: 'es2020', outDir: 'dist' } }));