-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
docs: clarify functionality of $env/* variables
#15078
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
base: main
Are you sure you want to change the base?
docs: clarify functionality of $env/* variables
#15078
Conversation
Clarify the purpose and access restrictions of the module.
Clarified the description and usage of the $env/dynamic/public module, including details on public access and environment variable handling.
Clarify notes on environment variable handling in dev and prod.
|
Ran these to double check and format the markdown files via Prettier. |
|
Agreed that it took me a while and trying/testing to fully figure it out. It's a similar concept though (might even be) to Vite's environment variable mechanism. So, if Vite has a page that fully deep dives on it, maybe it's better to link to there as well? |
I spent a lot of time trying to understand the `$env/* variables and how they behave, the docs didn't really seem very fleshed out and I was confused. I wrote up a bunch of demo code to make sure I really understood the behaviour, and then realized that a little love in the docs would probably be appreciated.
All sample code has been run locally and validated as correct as of
[email protected](using thenpx sv createto make a minimal app). Anything that required validation between dev and prod I rannpm run build, editing the.envfile as necessary, and thennpm run previewto run.The overall idea
Here's how I broke it down conceptually:
$env/dynamic/private$env/static/private$env/dynamic/public$env/static/publicPrivate versus public:
publicPrefix/privatePrefix.Runtime versus buildtime:
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
[ ] It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs[ ] Ideally, include a test that fails without this PR but passes with it.Tests
[ ] Run the tests withpnpm testand lint the project withpnpm lintandpnpm checkChangesets
[ ] If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by runningpnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.Edits