-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
46 lines (41 loc) · 1.26 KB
/
vite.config.js
File metadata and controls
46 lines (41 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react';
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
// Load all env vars including VITE_ prefixed ones
const env = loadEnv(mode, process.cwd(), '');
// Environment variables to inject
const envVars = [
'VITE_FIREBASE_API_KEY',
'VITE_FIREBASE_AUTH_DOMAIN',
'VITE_FIREBASE_DATABASE_URL',
'VITE_FIREBASE_PROJECT_ID',
'VITE_FIREBASE_STORAGE_BUCKET',
'VITE_FIREBASE_MESSAGING_SENDER_ID',
'VITE_FIREBASE_APP_ID',
'VITE_FIREBASE_MEASUREMENT_ID',
];
// Build define object - always inject, using process.env (Cloudflare) or loadEnv (local)
const define = {};
envVars.forEach(key => {
const value = process.env[key] ?? env[key] ?? '';
define[`import.meta.env.${key}`] = JSON.stringify(value);
});
// Debug: log what we're injecting during build
console.log('Vite build - Environment variables status:');
envVars.forEach(key => {
console.log(` ${key}: ${process.env[key] ? 'from process.env' : env[key] ? 'from .env' : 'MISSING'}`);
});
return {
plugins: [react()],
server: {
port: 3000,
open: true
},
build: {
outDir: 'dist',
sourcemap: true
},
define
};
});