Concern
Application configuration and environment-specific settings for the frontend (build-time and dev).
Technology
Vite environment variables (import.meta.env), env loading from root .env with prefix mapping
Documentation
- Vite env: https://vite.dev/guide/env-and-mode
- Stack rule
vitefor build and dev server
Integration
vite / build
Only variables prefixed with VITE_ are exposed to client code via import.meta.env; they are inlined at build time. Root .env uses FRONTEND_DESKTOP_ for the desktop app; a Vite plugin maps them to VITE_* so app code uses a single set of names.
http-client
API base URL and other client config come from import.meta.env.VITE_* (e.g. VITE_BACKEND_URL). See http-client for usage.
Configuration
- Root
.env: At monorepo root, desktop-related vars use theFRONTEND_DESKTOP_prefix for any vars other than the API URL. VITE_BACKEND_URL is not set in root; the desktop Vite config derives it ashttp://localhost:BACKEND_PORTonly when VITE_BACKEND_URL is not already set (dev default; deployed sets it at build time). FRONTEND_DESKTOP_PORT maps to VITE_PORT (dev server port; default 5173) via the genericFRONTEND_DESKTOP_*→VITE_*mapping. The desktop app’s Vite config setsenvDirto the monorepo root, loads root.env, mapsFRONTEND_DESKTOP_*→VITE_*, and sets VITE_BACKEND_URL tohttp://localhost:${BACKEND_PORT || '3000'}only when unset. App code only usesimport.meta.env.VITE_BACKEND_URLetc. - Optional overrides: A
.envinfrontends/desktop/withVITE_*if needed (e.g. for worktrees). - Deployment: The platform sets
VITE_*at build time (e.g.VITE_BACKEND_URL,VITE_ENVIRONMENT); root.envis for local dev.
Environment variables
- VITE_BACKEND_URL — API base URL for the frontend. Build-time (inlined). Dev: derived from BACKEND_PORT only when unset (
http://localhost:BACKEND_PORT); deployed: set at build (e.g./apifor same-origin)—never overridden when already set. Seehttp-client. - VITE_PORT — Dev server port (Vite
server.port). FRONTEND_DESKTOP_PORT in root.envmaps automatically to VITE_PORT via theFRONTEND_DESKTOP_*→VITE_*mapping; default 5173. - VITE_ENVIRONMENT — Optional; values
development,acceptance,production; build-time. Used bygetEnvironment()infrontends/shared; when unset and not dev server, treated as development. See patternenvironments.
App code reads only import.meta.env.VITE_*. Declare these in frontends/shared/src/env.d.ts so TypeScript and consumers (e.g. lib/api.ts, lib/environment.ts) are typed.
Implementation
The desktop app’s vite.config.ts sets envDir to the monorepo root and, at config load time, loads the root .env with dotenv, maps each FRONTEND_DESKTOP_* key to VITE_* (so FRONTEND_DESKTOP_PORT → VITE_PORT for the dev server), and sets VITE_BACKEND_URL to http://localhost:${BACKEND_PORT || '3000'} only when VITE_BACKEND_URL is undefined (dev default; deployed sets it at build time). server.port is set from VITE_PORT (default 5173). frontends/shared/src/env.d.ts declares VITE_BACKEND_URL, VITE_ENVIRONMENT, and other VITE_* vars. Root .env.example documents FRONTEND_DESKTOP_* vars; backend and frontend stack configuration and pattern configuration describe the overall convention.
References
- Pattern:
configuration(root .env, prefixes, strip/map),environments(VITE_ENVIRONMENT). - Stack:
vite,http-client,hosting.