Environment Variables
Zudoku is built on top of Vite and uses their approach for managing environment variables.
In Zudoku, environment variables that are prefixed with ZUDOKU_PUBLIC_
are available in your application.
Local Env Files
When developing locally, you can create a .env
file in the root of your project and add environment-specific variables. See the Vite documentation for more information on supported files.
Here is an example of a .env.local
file:
sh
You can access this variable in your application like this:
ts
Configuration Files
Environment variables can also be used in your configuration files. When referencing environment variables in your configuration files, you can use process.env
directly.
ts
React Components
If you need to access environment variables inside a custom react component, you can access them via import.meta.env
. Public environment variables are inlined during the build process.
tsx
IntelliSense for TypeScript
By default, Zudoku provides type definitions for import.meta.env
in zudoku/client.d.ts
. While you can define more custom env variables in .env.[mode]
files, you may want to get TypeScript IntelliSense for user-defined env variables that are prefixed with ZUDOKU_PUBLIC_
.
To achieve this, you can create a zudoku-env.d.ts
in src directory, then augment ImportMetaEnv
like this:
typescript
Imports will break type augmentation
If the ImportMetaEnv
augmentation does not work, make sure you do not have any import statements in vite-env.d.ts
. A helpful explanation can be found on this StackOverflow reply.