Replies: 3 comments 1 reply
-
I second that feature request. In my apps i have a script that runs a custom dev build that access remote database instead of local database I accomplish that with vite setting mode to "remote" In .env.remote i set a env variable "REMOTE_DATA" In app i check import.meta.env.REMOTE_DATA to connect to remote data even in dev build With astro this is not possible currently Also, the astro docs (https://docs.astro.build/en/guides/environment-variables/) is misleading as it states that can use "any methods supported by vite" to load env variables which is not true BTW setting env inline in the script command is a poor solution in my case since i develop both in windows and linux |
Beta Was this translation helpful? Give feedback.
-
Definitely support this feature request too. I went down quite a rabbit hole on this only to find out it's not implemented in Astro, especially since the official astro docs state that the |
Beta Was this translation helpful? Give feedback.
-
https://docs.astro.build/en/reference/programmatic-reference/#mode |
Beta Was this translation helpful? Give feedback.
-
Body
Summary
Support passing the
--mode
flag when runningastro dev
Background & Motivation
Following on from withastro/astro#10509
Vite has the incredibly useful
--mode
flag which allows you to load different.env.[MODE]
files. This flag is supported byvite build
andvite serve
.astro dev
does not use the--mode
flag,import.meta.env.MODE
is alwaysdevelopment
and only.env
and.env.development
are loaded.Switching between development and staging environments when running astro locally is especially difficult because of this limitation. The best solution at the moment seems to be renaming
.env.development
to swap out the variables needed for development/staging 🤢Coming from vite, this seems like a step backwards.
Goals
astro dev
command supports passing--mode
flag--mode
flag updatesimport.meta.env.MODE
--mode
flag controls which.env.[MODE]
file is loadedExample
With an app that logs
import.meta.env.MODE
on startup:Beta Was this translation helpful? Give feedback.
All reactions