Env Variables in Workers Static Site [Vite + React]

Hey All, I am building a React + Vite app using cloudflare workers. It is a SPA with no workers backend. Is there any documentation around how to get environment variables into the frontend React app? I see everything is focused on how to get them into the workers runtime, but I am looking to access them from the bundled React code, where I normally use import.meta.env with vite
1 Reply
Jonathan Riche
You need a .env with VITEENVNAME by default for Vite to read it(unless you changed the default in the vite config) the ```env VITE ``` tell vite its a public/client side facing env you need an underscore after VITE - discord keeps removing it when i add it..

Did you find this page helpful?