import { execFileSync } from 'node:child_process'; import { readFileSync } from 'node:fs'; import { fileURLToPath } from 'node:url'; import react from '@vitejs/plugin-react'; import { defineConfig } from 'vitest/config'; const webRoot = fileURLToPath(new URL('.', import.meta.url)); const webPackage = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8')) as { version: string }; function gitValue(...args: string[]): string { try { return execFileSync('git', args, { cwd: webRoot, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim() || 'unknown'; } catch { return 'unknown'; } } const buildInfo = { frontendVersion: webPackage.version, frontendCommit: process.env.WEBDROP_FRONTEND_COMMIT ?? gitValue('rev-parse', 'HEAD'), frontendTag: process.env.WEBDROP_FRONTEND_TAG ?? gitValue('describe', '--tags', '--exact-match', 'HEAD'), backendCommit: process.env.WEBDROP_BACKEND_COMMIT ?? gitValue('rev-parse', 'HEAD'), backendTag: process.env.WEBDROP_BACKEND_TAG ?? gitValue('describe', '--tags', '--exact-match', 'HEAD'), builtAt: process.env.WEBDROP_BUILD_TIME ?? new Date().toISOString(), }; export default defineConfig({ plugins: [react()], define: { __WEBDROP_BUILD_INFO__: JSON.stringify(buildInfo) }, resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)), '@webdrop/core': fileURLToPath(new URL('../packages/core/src/index.ts', import.meta.url)), }, }, build: { target: 'es2022', sourcemap: false }, server: { proxy: { '/api/v1': { target: process.env.WEBDROP_DEV_API_TARGET ?? 'http://127.0.0.1:5000', ws: true } } }, test: { environment: 'node' }, });