I have a vite project that works great locally but fails when deploying with Docker - and I know why but I don't know what to do about it.
Certain secrets (oauth) are defined in .env and referenced in code with import.meta.env. Running locally it reads .env no problem. Even building into a container works fine, except those secrets are baked into the container, which isn't great.
The vite documentation clearly explains that those values are baked in at build time.
I'd like to understand from the community what the general best practices are with import.meta.env. If I read it as "env vars at build time" then it fits into place. But I'd mistakenly thought it would "use build time after reading current env", which it absolutely does not do.
This article clearly explains one way to work around it, but that only worked for the SSR parts for me, not the client - can't figure out why.
I think the solution is to take this view, but I would love your input:
- Use
import.meta.envfor values from .env at compile and build time - If you want to read the local env first, then do that in code, then fall back to
import.meta.env.
Thoughts?
#1019670660856942652 #deploy #docker