Skip to content

Instantly share code, notes, and snippets.

@tomek-f
Created March 6, 2025 10:06
Show Gist options
  • Save tomek-f/9b16daf8706821b83e2c0a951124f35c to your computer and use it in GitHub Desktop.
Save tomek-f/9b16daf8706821b83e2c0a951124f35c to your computer and use it in GitHub Desktop.
process.env.* on Vite app
import { loadEnv } from 'vite';
import type { UserConfig } from 'vite';
const config = ({ mode = 'development' }: UserConfig) => {
const env = loadEnv(mode, process.cwd(), 'MF');
return {
define: Object.fromEntries(
Object.entries(env).map(([key, value]) => [`process.env.${key}`, JSON.stringify(value)]),
),
// other stuff here
}
}
export default config;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment