// Copyright (c) 2026 Gordon Bolton. MIT License. import { defineConfig, loadEnv } from 'vite' import path from 'path' export default defineConfig(({ mode }) => { // Load env variables from root directory to match backend TLS configuration const env = loadEnv(mode, path.resolve(__dirname, '..'), ''); const port = env.PORT || 3001; const tlsEnabled = (env.TLS_ENABLED || 'true').toLowerCase() !== 'false'; const target = `${tlsEnabled ? 'https' : 'http'}://localhost:${port}`; return { build: { // NOTE (Issue #66): `outDir` is intentionally the repo-root `../public`, // NOT the Vite default `client/dist/`. The Express server in // `server/app.js` serves static assets directly from `public/`, so the // Vite build emits its bundle alongside the hand-authored static assets // (favicon, etc.) that live in `public/` and are committed to the repo. // Do NOT change this back to `dist/` without also updating the Express // static-serve configuration and the Dockerfile copy steps. outDir: '../public', // NOTE (Issue #66): `emptyOutDir: false` is REQUIRED because `public/` // contains hand-authored static assets that must survive the build. // Setting this to `true` would wipe those assets on every `vite build`. emptyOutDir: false, rollupOptions: { input: { main: './src/main.js' }, output: { entryFileNames: 'app.js', chunkFileNames: '[name].js', assetFileNames: '[name][extname]' } } }, server: { port: 5173, host: true, // Listen on all network interfaces proxy: { '/api': { target: target, changeOrigin: true, secure: false // Allow self-signed certificate in development } } } }; });