One handles environment variables for you in a few ways.
First, it handles loading .env files during development and in production. In order to ease compatibility with ESM and CJS, One makes your loaded environment variables (from .env and from process.env) automatically be defined onto both import.meta.env and process.env.
Second, One ensures that all environment variables loaded are only available to the server-side functionality, unless they are prefixed with either VITE_ (to match Vite convention) or ONE_PUBLIC_.
So, for example ONE_PUBLIC_DAYTIME=false one dev would set both process.env.ONE_PUBLIC_DAYTIME and import.meta.env.ONE_PUBLIC_DAYTIME to be the string "false" on both server and client.
But, SOME_RANDOM_VAR=2 would not be exposed to the client side, because it lacks the appropriate prefix.
One also sets some environment variables for you, available on both process.env and import.meta.env.
ONE_CACHE_KEY is set to a random number for each production build, or stable per dev server run. Useful for cache keys.ONE_APP_NAME is set to your app.key setting.ONE_SERVER_URL is set in development mode to the current running server URL, like http://0.0.0.0:8081. You are expected to set this yourself for production builds.ONE_DEFAULT_RENDER_MODE is set to either "ssr", "ssg", or "spa" based on your defaultRenderMode setting.VITE_ENVIRONMENT is set to "client" for client-side web, "ssr" for server-side web, or "ios" / "android" for native platforms.VITE_PLATFORM is set to "web" for web builds (both client and SSR), or "native" for native platforms (iOS and Android). Useful for branching on web vs native without checking multiple OS values.EXPO_OS is set to "web" for web builds (both client and SSR), or "ios" / "android" for native platforms. This matches the Expo convention for platform detection.Available in native builds:
REACT_NATIVE_VERSION contains the React Native version string.REACT_NATIVE_PLATFORM is set to "ios" or "android" in native builds.One provides TypeScript types for all preset environment variables. To enable them, add a triple-slash reference to your project:
/// <reference types="one/env" />
You can add this to any .d.ts file in your project (such as env.d.ts or vite-env.d.ts), or include it in a file that's part of your TypeScript compilation.
This gives you autocomplete and type checking for import.meta.env.VITE_ENVIRONMENT, process.env.VITE_PLATFORM, and all other One environment variables.
Edit this page on GitHub.