import { defineConfig, type Plugin } from 'vite' import vue from '@vitejs/plugin-vue' import tailwindcss from '@tailwindcss/vite' // The committed build is path-agnostic (D-02): assets use a relative base and // index.html keeps the __SUMMER_ADMIN_BASE__ token, which the Go server // (boardwalk) replaces with the configured backend.uri. The dev server // replaces it with SUMMER_ADMIN_DEV_PREFIX and proxies the admin API and the // plugin assets to a running `summer serve` at SUMMER_ADMIN_DEV_TARGET. const devPrefix = (process.env.SUMMER_ADMIN_DEV_PREFIX ?? '/backend').replace(/\/+$/, '') const devTarget = process.env.SUMMER_ADMIN_DEV_TARGET ?? 'http://localhost:8080' function devBase(): Plugin { return { name: 'summer-admin-dev-base', apply: 'serve', transformIndexHtml: (html) => html.replace('__SUMMER_ADMIN_BASE__', devPrefix), } } export default defineConfig(({ command }) => ({ base: command === 'build' ? './' : '/', plugins: [vue(), tailwindcss(), devBase()], build: { outDir: '../modules/boardwalk/dist', emptyOutDir: true, sourcemap: false, }, server: { proxy: { [`${devPrefix}/api`]: { target: devTarget, changeOrigin: false }, // Plugin JS/CSS that controllers declare (Phase 10.1), served by cabana. [`${devPrefix}/assets`]: { target: devTarget, changeOrigin: false }, }, }, }))