#How to properly do .env with vite and netlify?

1 messages · Page 1 of 1 (latest)

blissful depot
#

QUESTION:
With Vite, how should I handle .env files for api keys? do you use the VITE_SOME_KEY naming structure and then just use
import.meta.env.VITE_SOME_KEY
?

I'm trying to understand how this works in Netlify, do I just define it like this (image) when deploying ?

placid pivot
#

Yes, use import.meta.env.VITE_SOME_KEY in your code. You have to prepend each variable with VITE if you want it bundled in client code. If server side, use process.env.SOME_KEY. To use the variables in netlify it is exactly like your screen shot. It has to use the same variable name and same value for that variable to work.