import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' import { execSync } from 'child_process' import fs from 'fs' // Read version from package.json const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf-8')) const appVersion = packageJson.version // Get git commit hash const gitHash = execSync('git rev-parse --short HEAD').toString().trim() export default defineConfig({ plugins: [ react(), { name: 'html-transform', transformIndexHtml(html) { return html.replace(/__APP_VERSION__/g, appVersion); } } ], base: '/', // Always use root, since we're Cloudflare Pages only publicDir: 'public', // ← Explicitly set (should be default) build: { outDir: 'dist', emptyOutDir: false, }, define: { '__APP_VERSION__': JSON.stringify(appVersion), '__BUILD_HASH__': JSON.stringify(gitHash), '__BUILD_TIMESTAMP__': JSON.stringify(new Date().toISOString()), } })