@@ -2,7 +2,7 @@ import { execSync } from "node:child_process";
22import { copyFileSync , existsSync , mkdirSync } from "node:fs" ;
33import path , { join } from "node:path" ;
44import { fileURLToPath } from "node:url" ;
5- import { defineConfig , type Plugin } from "vite" ;
5+ import { defineConfig , loadEnv , type Plugin } from "vite" ;
66import tsconfigPaths from "vite-tsconfig-paths" ;
77import { autoServicesPlugin } from "./vite-plugin-auto-services.js" ;
88
@@ -154,48 +154,60 @@ function copyClaudeExecutable(): Plugin {
154154// Allow forcing dev mode in packaged builds via FORCE_DEV_MODE=1
155155const forceDevMode = process . env . FORCE_DEV_MODE === "1" ;
156156
157- export default defineConfig ( {
158- plugins : [
159- tsconfigPaths ( ) ,
160- autoServicesPlugin ( join ( __dirname , "src/main/services" ) ) ,
161- fixFilenameCircularRef ( ) ,
162- copyAgentTemplates ( ) ,
163- copyClaudeExecutable ( ) ,
164- ] ,
165- define : {
166- __BUILD_COMMIT__ : JSON . stringify ( _getGitCommit ( ) ) ,
167- __BUILD_DATE__ : JSON . stringify ( _getBuildDate ( ) ) ,
168- ...( forceDevMode
169- ? {
170- "import.meta.env.DEV" : "true" ,
171- "import.meta.env.PROD" : "false" ,
172- "import.meta.env.MODE" : '"development"' ,
173- }
174- : { } ) ,
175- } ,
176- resolve : {
177- alias : {
178- "@" : path . resolve ( __dirname , "./src" ) ,
179- "@main" : path . resolve ( __dirname , "./src/main" ) ,
180- "@renderer" : path . resolve ( __dirname , "./src/renderer" ) ,
181- "@shared" : path . resolve ( __dirname , "./src/shared" ) ,
182- "@api" : path . resolve ( __dirname , "./src/api" ) ,
157+ export default defineConfig ( ( { mode } ) => {
158+ // Load VITE_* env vars from monorepo root .env file
159+ const env = loadEnv ( mode , path . resolve ( __dirname , "../.." ) , "VITE_" ) ;
160+
161+ return {
162+ plugins : [
163+ tsconfigPaths ( ) ,
164+ autoServicesPlugin ( join ( __dirname , "src/main/services" ) ) ,
165+ fixFilenameCircularRef ( ) ,
166+ copyAgentTemplates ( ) ,
167+ copyClaudeExecutable ( ) ,
168+ ] ,
169+ define : {
170+ __BUILD_COMMIT__ : JSON . stringify ( _getGitCommit ( ) ) ,
171+ __BUILD_DATE__ : JSON . stringify ( _getBuildDate ( ) ) ,
172+ // Inject PostHog env vars at build time (process.env is not available in packaged builds)
173+ "process.env.VITE_POSTHOG_API_KEY" : JSON . stringify (
174+ env . VITE_POSTHOG_API_KEY || "" ,
175+ ) ,
176+ "process.env.VITE_POSTHOG_API_HOST" : JSON . stringify (
177+ env . VITE_POSTHOG_API_HOST || "" ,
178+ ) ,
179+ ...( forceDevMode
180+ ? {
181+ "import.meta.env.DEV" : "true" ,
182+ "import.meta.env.PROD" : "false" ,
183+ "import.meta.env.MODE" : '"development"' ,
184+ }
185+ : { } ) ,
183186 } ,
184- } ,
185- cacheDir : ".vite/cache" ,
186- build : {
187- target : "node18" ,
188- minify : false ,
189- reportCompressedSize : false ,
190- commonjsOptions : {
191- transformMixedEsModules : true ,
187+ resolve : {
188+ alias : {
189+ "@" : path . resolve ( __dirname , "./src" ) ,
190+ "@main" : path . resolve ( __dirname , "./src/main" ) ,
191+ "@renderer" : path . resolve ( __dirname , "./src/renderer" ) ,
192+ "@shared" : path . resolve ( __dirname , "./src/shared" ) ,
193+ "@api" : path . resolve ( __dirname , "./src/api" ) ,
194+ } ,
192195 } ,
193- rollupOptions : {
194- external : [ "node-pty" , "@parcel/watcher" , "file-icon" ] ,
195- onwarn ( warning , warn ) {
196- if ( warning . code === "UNUSED_EXTERNAL_IMPORT" ) return ;
197- warn ( warning ) ;
196+ cacheDir : ".vite/cache" ,
197+ build : {
198+ target : "node18" ,
199+ minify : false ,
200+ reportCompressedSize : false ,
201+ commonjsOptions : {
202+ transformMixedEsModules : true ,
203+ } ,
204+ rollupOptions : {
205+ external : [ "node-pty" , "@parcel/watcher" , "file-icon" ] ,
206+ onwarn ( warning , warn ) {
207+ if ( warning . code === "UNUSED_EXTERNAL_IMPORT" ) return ;
208+ warn ( warning ) ;
209+ } ,
198210 } ,
199211 } ,
200- } ,
212+ } ;
201213} ) ;
0 commit comments