-
Notifications
You must be signed in to change notification settings - Fork 16
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
fix: env refactor for Vite wrap-up [LIBS-690] #889
Merged
Merged
+669
−954
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
amcgee
approved these changes
Oct 30, 2024
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.
Code LGTM
dhis2-bot
added a commit
that referenced
this pull request
Oct 30, 2024
# [12.0.0-alpha.21](v12.0.0-alpha.20...v12.0.0-alpha.21) (2024-10-30) ### Bug Fixes * env refactor for Vite wrap-up [LIBS-690] ([#889](#889)) ([84da4e6](84da4e6))
🎉 This PR is included in version 12.0.0-alpha.21 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
dhis2-bot
added a commit
that referenced
this pull request
Dec 13, 2024
# [12.0.0](v11.7.5...v12.0.0) (2024-12-13) ### Bug Fixes * **deps:** upgrade app-runtime and ui ([#895](#895)) ([8ed0ec3](8ed0ec3)) * **deps:** upgrade react to 18 in example apps ([#900](#900)) ([7fd16d7](7fd16d7)) * **deps:** use npm v6 before publishing ([01ad502](01ad502)) * **init:** update bootstrap script branch ([#896](#896)) ([33c261a](33c261a)) * **plugin:** clean up resize observer and handle sonarqube warnings ([#898](#898)) ([f113dd5](f113dd5)) * alerts from plugins [LIBS-695] ([#881](#881)) ([21be0d2](21be0d2)) * allow serving files from cwd node_modules ([0233949](0233949)) * base url env & refactor [LIBS-635] ([#872](#872)) ([7f19259](7f19259)) * bump ui library ([#882](#882)) ([1ae9569](1ae9569)) * clear only required build dirs ([#894](#894)) ([179305f](179305f)) * env refactor for Vite wrap-up [LIBS-690] ([#889](#889)) ([84da4e6](84da4e6)) * injectPrecacheManifest warning logging ([a0d266e](a0d266e)) * normalize to .js extensions when compiling libraries ([#893](#893)) ([58b33a8](58b33a8)) * **service-worker:** handle undefined config vars in injectPrecacheManifest ([a90a4e0](a90a4e0)) * correct app shell paths ([#883](#883)) ([a1af71c](a1af71c)) * handle jsx in js support [LIBS-633] ([#871](#871)) ([595a35d](595a35d)) * increase precache max file size to 3 MB ([b20ed22](b20ed22)) * remove custom eslint from TS template ([71cef4b](71cef4b)) * update deps ([1e7ce93](1e7ce93)) * update workbox deps to avoid deprecation warnings ([9a81c4a](9a81c4a)) * use strings for 'boolean' env vars ([eaf5e66](eaf5e66)) ### Features * create initial TS template ([#868](#868)) ([2795f79](2795f79)) * enable HMR for .js files ([5f4683c](5f4683c)) * handle plugins with Vite [LIBS-610] ([#863](#863)) ([ca5be0d](ca5be0d)) * jsx migration script ([#869](#869)) ([7764f49](7764f49)) * migrate snap files too ([#878](#878)) ([521f483](521f483)) * replace CRA with Vite [LIBS-598] ([#847](#847)) ([3dd0e59](3dd0e59)) * upgrade react to v18 ([#876](#876)) ([77ecf10](77ecf10)) * **init:** set direction: 'auto' and import locales for new apps [LIBS-645] ([#867](#867)) ([4eda4a9](4eda4a9)) ### BREAKING CHANGES * require react version 18 * fix: pin react version to 18 * test: update test and test libraries for react 18 * Supported Node versions are 18.x or 20+ * ci: upgrade Node version * fix: always add PWA_ENABLED to app env for better static analysis * chore: pause precache manifest injection * fix: building SW without CRA * chore: comment update * fix: group moment locales in their own dir * refactor: clean up precache injection * fix: locale utils and handling moment in jest * fix: compile correctly after merging changes * chore: comment in compile.js * chore: some clean-up * chore: comments * fix: use port 3000 for the dev server * fix: improve moment locale chunk naming * chore: remove CRA * fix: use mjs build of Vite * fix: bump cli-style for CRA fix * feat: use interactive dev server output from Vite * fix: make dev server port configurable * chore: remove old index.html * fix: env tweaks
🎉 This PR is included in version 12.0.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Part of LIBS-690
process.env
vs.import.meta.env
Vite adds environment variables to the
import.meta.env
namespace by default. My plan was to make this the standard for the platform, too, because I thought this was a standard format that goes along with ES Modules. It turns out that it’s not standard, actually; it’s a pattern specific to Vite. Other build tools tend to useprocess.env
as the default.I've noticed that there are some other tools and packages out there that depend on configuration variables that are set on
process.env
, so dropping support for it entirely in favor ofimport.meta.env
may be a bit weird.This makes me think we should continue adding env vars to
process.env
, since it’s a little more generic, instead of migrating entirely toimport.meta.env
as the main env var namespace for the platform.We can still deprecate the
REACT_APP_
-prefixed variable names, i.e.process.env.REACT_APP_DHIS2_APP_VERSION
=>process.env.DHIS2_APP_VERSION
. We can handle it in the same way we planned to handle moving toimport.meta.env
i.e., have both variable names available in v12, then remove theREACT_APP_
versions in v13.If we do, I’m not sure how much attention to give
import.meta.env
— Right now, Vite is configured to filter the env for values starting with “DHIS2_” and add them toimport.meta.env
. It seems that only values onimport.meta.env
can be used in HTML files, like%DHIS2_APP_NAME%
inindex.html
. I propose we kinda keepimport.meta.env
as-is; some people may want to use it, and it doesn't really hurt to add theDHIS2_
prefixed env vars onto it.Other env vars
I made some other changes to make the env var objects more concise:
undefined
valuesundefined
values from the envI tested these out by starting and building both the simple-app and pwa-app examples to make sure they work with and without env vars. I also inspected the SW's caching behavior in the PWA app, and it looks good.
Examples
Before:
After: