You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to validate env vars coming from .env as well as from the system.
System environment:
EXPORT SENTRY_AUTH_TOKEN=sensitivevalue
.env:
VITE_APP_VAR=publicvalue
vite.config.ts:
export default defineConfig(({ mode, command }) => {
process.env = {
...process.env,
...loadEnv(mode, process.cwd(), "VITE_APP_")
};
return {
envPrefix: "VITE_APP_", // Default env prefix
plugins: [
// Validate environment variables from .env file prefixed with VITE_APP_
// that are used in the application and will end up in the bundle
ValidateEnv({
validator: "builtin",
schema: {
VITE_APP_VAR: Schema.string()
}
}),
[
// Validate sensitive environment variables from system that doesn't have prefix
// and should never end up in the bundle
{
...ValidateEnv({
validator: "builtin",
schema: {
SENTRY_AUTH_TOKEN: Schema.string()
}
}),
apply: "build"
},
{
...sentryVitePlugin({
authToken: process.env.SENTRY_AUTH_TOKEN // Use sensitive env variable here
}),
apply: "build"
}
]
]
};
});
Above won't work because we're only able to validate vars prefixed with envPrefix (VITE_APP_), hence SENTRY_AUTH_TOKEN will always report as missing.
Do you think there's a way to achieve this? Would you accept a PR, and if so, any pointers how you'd like it done?
The text was updated successfully, but these errors were encountered:
biesbjerg
changed the title
Allow validating all env vars
Allow validating env vars without prefix
Apr 16, 2024
It loads all environment variables, enabling validation, but only exposes variables (through define) if their keys begin with the configured envPrefix.
I'd like to validate env vars coming from
.env
as well as from the system.System environment:
.env
:vite.config.ts
:Above won't work because we're only able to validate vars prefixed with
envPrefix
(VITE_APP_
), henceSENTRY_AUTH_TOKEN
will always report as missing.Do you think there's a way to achieve this? Would you accept a PR, and if so, any pointers how you'd like it done?
The text was updated successfully, but these errors were encountered: