Skip to content

Commit 33ff4e7

Browse files
authored
fix: build (#188)
1 parent 9f7837b commit 33ff4e7

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

src/lib/env.ts

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ const isBrowser = typeof window !== 'undefined';
1919
function getEnvVar(viteKey: string, serverKey?: string): string {
2020
if (isBrowser) {
2121
// Browser: Only access VITE_* prefixed variables via import.meta.env
22-
try {
23-
return (import.meta as any).env?.[viteKey] || '';
24-
} catch {
25-
// Fallback if import.meta is not available
26-
return '';
27-
}
22+
// Use optional chaining and fallback for production compatibility
23+
const metaEnv = (typeof import.meta !== 'undefined' && (import.meta as any).env) || {};
24+
const value = metaEnv[viteKey];
25+
return value || '';
2826
} else {
2927
// Server: Use process.env only (import.meta.env not available in CommonJS/Netlify Functions)
3028
return process.env[viteKey] || (serverKey ? process.env[serverKey] : '') || '';
@@ -64,33 +62,24 @@ export const env = {
6462
// Development mode detection
6563
get DEV() {
6664
if (isBrowser) {
67-
try {
68-
return (import.meta as any).env?.DEV || false;
69-
} catch {
70-
return false;
71-
}
65+
const metaEnv = (typeof import.meta !== 'undefined' && (import.meta as any).env) || {};
66+
return metaEnv.DEV || false;
7267
}
7368
return process.env.NODE_ENV === 'development';
7469
},
7570

7671
get PROD() {
7772
if (isBrowser) {
78-
try {
79-
return (import.meta as any).env?.PROD || false;
80-
} catch {
81-
return false;
82-
}
73+
const metaEnv = (typeof import.meta !== 'undefined' && (import.meta as any).env) || {};
74+
return metaEnv.PROD || false;
8375
}
8476
return process.env.NODE_ENV === 'production';
8577
},
8678

8779
get MODE() {
8880
if (isBrowser) {
89-
try {
90-
return (import.meta as any).env?.MODE || 'development';
91-
} catch {
92-
return 'development';
93-
}
81+
const metaEnv = (typeof import.meta !== 'undefined' && (import.meta as any).env) || {};
82+
return metaEnv.MODE || 'development';
9483
}
9584
return process.env.NODE_ENV || 'development';
9685
},

vite.config.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,15 @@ export default defineConfig({
6262
// Remove the external configuration as it's causing build issues
6363
output: {
6464
// Ensure proper file extensions for module recognition
65-
entryFileNames: 'assets/[name]-[hash].js',
66-
chunkFileNames: 'assets/[name]-[hash].js',
65+
entryFileNames: (chunkInfo) => {
66+
// Force .js extension for all entry files, including App
67+
const name = chunkInfo.name?.replace(/\.tsx?$/, '') || 'chunk';
68+
return `assets/${name}-[hash].js`;
69+
},
70+
chunkFileNames: (chunkInfo) => {
71+
// Force .js extension for all chunk files
72+
return `assets/${chunkInfo.name}-[hash].js`;
73+
},
6774
assetFileNames: 'assets/[name]-[hash].[ext]',
6875
// Proven chunk splitting strategy from LIGHTHOUSE_OPTIMIZATIONS.md
6976
manualChunks: {

0 commit comments

Comments
 (0)