-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support loading customize environment variables from a .env file #223
Conversation
Good job! |
FYI: inlining the entire env object like this leads to bloated bundle size and also cause the minifier to not be able to drop This will also remove support for usage like |
See 1be6121 |
Anyone got a walkthrough doc of how to use this? I am trying to use vs what I have in .env I am using svite: https://github.com/quantuminformation/mentorcv/blob/master/src/index.js#L2 |
@quantuminformation try prefixing your environment variables with |
wow that was quick, yes that works thx |
Only variables prefixed with VITE_ are exposed to your code. e.g. VITE_SOME_KEY=123 will be exposed as import.meta.env.VITE_SOME_KEY, but SOME_KEY=123 will not. This is because the .env files may be used by some users for server-side or build scripts and may contain sensitive information that should not be exposed in code shipped to browsers. // src/node/config.ts line:455
function loadEnv(mode: string, root: string): Record<string, string> {
if (mode === 'local') {
throw new Error(
`"local" cannot be used as a mode name because it conflicts with ` +
`the .local postfix for .env files.`
)
}
debug(`env mode: ${mode}`)
const envFiles = [
/** mode local file */ `.env.${mode}.local`,
/** mode file */ `.env.${mode}`,
/** local file */ `.env.local`,
/** default file */ `.env`
]
const env: Record<string, string> = {}
for (const file of envFiles) {
const path = lookupFile(root, [file], true)
if (path) {
const result = dotenv.config({
debug: !!process.env.DEBUG || undefined,
path
})
if (result.error) {
throw result.error
}
dotenvExpand(result)
for (const key in result.parsed) {
// only keys that start with VITE_ are exposed.
if (key.startsWith(`VITE_`)) {
env[key] = result.parsed![key]
}
}
}
} |
Nice work guys, i'll promote this build tool on my YouTube channel later today. |
btw if any member/contributor wants to come on my podcast to talk about vite, please ping me. |
For some reason, I only get one environment var coming through
|
|
Reinstalled nod mods, went away! thx |
I tried passing in from command line
however |
No description provided.