import { fileURLToPath, URL } from 'node:url'; import { defineConfig, loadEnv } from 'vite'; import vue from '@vitejs/plugin-vue'; import { appVersion } from '../../scripts/app-version.mjs'; import { brand } from '../../brand'; // Ported from legacy henza_admin/vue.config.js. // The legacy build switched publicPath/outputDir on NODE_ENV=='branch'; in Vite the // equivalent switch is the --mode flag (`pnpm dev:branch` / `pnpm build:branch`), // which src/utils/index.ts reads via import.meta.env.MODE. export default defineConfig(({ mode }) => { const isBranch = mode === 'branch'; // Ports are defined once in the repo-root .env (ADMIN_PANEL_PORT / API_PORT) // — see that file's comment block. envDir points here so `vite` picks it up // even though this app's own directory has no .env of its own. const rootEnv = loadEnv(mode, fileURLToPath(new URL('../..', import.meta.url)), ''); const port = Number(rootEnv.ADMIN_PANEL_PORT ?? 5180); const apiPort = Number(rootEnv.API_PORT ?? 3000); // Same-host deploy: user app at `/`, admin at `/admin` (Dokploy Path + Strip Path). // Browser still loads `/admin/assets/…`; the proxy strips `/admin` before nginx. // Subdomain-only deploys can set ADMIN_PANEL_BASE=/ . Vite requires a trailing slash. const rawBase = (rootEnv.ADMIN_PANEL_BASE || '/admin/').trim() || '/admin/'; const adminBase = rawBase.endsWith('/') ? rawBase : `${rawBase}/`; return { envDir: fileURLToPath(new URL('../..', import.meta.url)), // Branch mode still mounts under `/branch/` when that mode is used. base: isBranch ? '/branch/' : adminBase, // Build number + «what changed» notes → version.json (scripts/app-version.mjs). plugins: [ vue(), appVersion('admin-panel'), //