feat(desktop): bridge MAIN_VITE_API_URL to process.env for packaged builds

In packaged Electron builds, @multica/core is externalized and .env
files are excluded. Bridge import.meta.env.MAIN_VITE_API_URL (injected
at build time by electron-vite) to process.env.MULTICA_API_URL so that
getApiBaseUrl() reads the correct value in staging/test environments.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
yushen 2026-02-14 07:30:42 +08:00
parent b8aa5ad7e6
commit b7477cb646
2 changed files with 8 additions and 0 deletions

View file

@ -5,6 +5,7 @@
interface ImportMetaEnv {
readonly MAIN_VITE_GATEWAY_URL: string
readonly MAIN_VITE_WEB_URL: string
readonly MAIN_VITE_API_URL?: string
}
interface ImportMeta {

View file

@ -44,6 +44,13 @@ process.stderr?.on?.('error', (err: NodeJS.ErrnoException) => {
throw err
})
// Bridge Vite build-time env to process.env for externalized @multica/core
// In dev mode, electron-vite already loads .env into process.env;
// In packaged builds, only import.meta.env has the value (injected at build time).
if (import.meta.env.MAIN_VITE_API_URL) {
process.env.MULTICA_API_URL ??= import.meta.env.MAIN_VITE_API_URL
}
import { app, BrowserWindow, shell, ipcMain } from 'electron'
import { fileURLToPath } from 'node:url'
import path from 'node:path'