-
|
Hi guys, I'm not sure how and where to properly expose (private) environment variables to make them accessible in the context of SvelteKit/Vite and also for various standalone scripts I use, mostly for seeding the database. I'm currently exposing them under import { loadEnvFile } from "node:process"
const load = (file: string): void => {
try {
loadEnvFile(file)
} catch (e) {
if (e.code !== "ENOENT") throw e
}
}
const dev = "development"
export const mode = import.meta.env?.MODE ?? process.env.NODE_ENV ?? dev
export const isDev = mode === dev
// load in the same order as Vite
load(".env")
load(".env.local")
load(`.env.${mode}`)
load(`.env.${mode}.local`)Is that reasonable? Are there any tricks for this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Vite actually has an export to load environment variables named |
Beta Was this translation helpful? Give feedback.
Vite actually has an export to load environment variables named
loadEnv. We're using this under the hood too and that should give you similar behaviour. Once #15250 is merged, you should also be able to just use the SvelteKit APIs for your standalone scripts