-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose private .env
variables to import.meta.env
during SSR
#2612
Conversation
🦋 Changeset detectedLatest commit: b1acfa4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea but no need to rush the implementation! I would love to see a pass to clean up the code a bit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweetening the release, @natemoo-re. 💯
if (!/\benv\b/.test(source)) return source; | ||
|
||
if (typeof privateEnv === 'undefined') { | ||
privateEnv = getPrivateEnv(config, astroConfig); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a little worried about caching issues here if Vite has automatic-reloading of .env files. Not enough to block, just a callout that could deserve a TODO if someone runs into this issue in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good callout. Just checked and Vite does not hot-reload .env
files.
LGTM with a failing test. Reminder that we don't need to race the train on this one: we can get it out in the next release if needed |
875c58a
to
dd92092
Compare
dd92092
to
2745569
Compare
…astro#2612) * chore(examples): add env-vars example * feat: improve import.meta.env support * chore: add changeset * test: update astro-envs test * refactor: cleanup code based on feedback * fix: import.meta guard * fix: update memory test threshold to 10%
…astro#2612) * chore(examples): add env-vars example * feat: improve import.meta.env support * chore: add changeset * test: update astro-envs test * refactor: cleanup code based on feedback * fix: import.meta guard * fix: update memory test threshold to 10%
Changes
.env
variables toimport.meta.env
on the server (during SSR).PUBLIC_
variables toimport.meta.env
on the client.env-vars
Testing
Tested manually in example
Docs
Updated in PR