import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' import tailwindcss from '@tailwindcss/vite' import fs from 'node:fs' import path from 'node:path' import { fileURLToPath } from 'node:url' const __dirname = path.dirname(fileURLToPath(import.meta.url)) function getAppVersion(): string { if (process.env.VITE_APP_VERSION) { return process.env.VITE_APP_VERSION } const candidatePaths = [ path.resolve(__dirname, '../version.ini'), path.resolve(__dirname, 'version.ini'), path.resolve(process.cwd(), '../version.ini'), path.resolve(process.cwd(), 'version.ini'), ] for (const p of candidatePaths) { if (fs.existsSync(p)) { try { const content = fs.readFileSync(p, 'utf-8') const match = content.match(/^version\s*=\s*([^\r\n]+)/m) if (match) { return match[1].trim().replace(/^["']|["']$/g, '') } } catch (err) { console.warn(`Failed to read version from ${p}:`, err) } } } return '1.0' } const appVersion = getAppVersion() // https://vite.dev/config/ export default defineConfig({ plugins: [ react(), tailwindcss(), ], define: { 'import.meta.env.VITE_APP_VERSION': JSON.stringify(appVersion), }, server: { port: 5173, proxy: { '/api': { target: 'http://127.0.0.1:8000', changeOrigin: true, }, '/ws': { target: 'ws://127.0.0.1:8000', ws: true, } } } })