-
Notifications
You must be signed in to change notification settings - Fork 5
Closed
Labels
@arkenv/vite-pluginIssues or Pull Requests involving the Vite plugin for ArkEnvIssues or Pull Requests involving the Vite plugin for ArkEnvenhancementNew feature or requestNew feature or request
Description
When using @arkenv/vite-plugin in a Vite + React project, the plugin validates environment variables at build time but doesn't provide a type-safe way to access them in the frontend runtime. Vite only exposes environment variables prefixed with VITE_ to import.meta.env, but there's no exported, validated env object to import.
Steps to Reproduce:
- Create a React template with Vite.
- Install
@arkenv/vite-pluginand configure it invite.config.ts. - Try to import the validated env object in frontend code.
- Result: No env object is exported, must manually access
import.meta.env.VITE_*.
Expected behavior:
The plugin should export a type-safe env object that can be imported in frontend code, similar to how createEnv works in Node environments.
Current workaround:
Manually access each variable via import.meta.env:
// No type safety, no validation at runtime
const apiUrl = import.meta.env.VITE_API_URL;Desired API:
import { env } from "virtual:arkenv";
// Type-safe and validated
const apiUrl = env.VITE_API_URL;Related:
- Support Bun frontend
process.envprefixing (e.g.BUN_PUBLIC_*) #181 (Bun frontendprocess.envprefixing) - bug: vite typescript does not infer the environment variables type. #195 (Alternative approach to support typesafe access in Vite, via
import.meta.env)
Action Items:
- Export a virtual module that provides the validated env object.
- Support configurable prefix (default:
VITE_*). - Ensure TypeScript types are generated for the virtual module.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
@arkenv/vite-pluginIssues or Pull Requests involving the Vite plugin for ArkEnvIssues or Pull Requests involving the Vite plugin for ArkEnvenhancementNew feature or requestNew feature or request