-
-
Notifications
You must be signed in to change notification settings - Fork 375
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
feat: add 'PREACT_APP_' prefixed env vars automatically & pickup .env file #1671
Conversation
🦋 Changeset detectedLatest commit: 4fe11a8 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 |
13fb76f
to
a10a516
Compare
a10a516
to
6180703
Compare
One thing that came up is the question of whether the |
packages/cli/lib/commands/watch.js
Outdated
let cwd = resolve(argv.cwd); | ||
require('dotenv').config({ path: resolve(cwd, '.env') }); |
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.
let cwd = resolve(argv.cwd); | |
require('dotenv').config({ path: resolve(cwd, '.env') }); | |
require('dotenv').config(); |
Wouldn't this work as well?
https://github.com/motdotla/dotenv#path
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.
In normal circumstances, sure.
However, that would break in our test suite (and probably mono-repos too): procces.cwd()
(which dotenv
uses) would differ from the project root.
I ran into that issue and moved the dotenv
setup here accordingly.
Sorry, that could've done with a comment.
Edit: Added comments to both usages.
Could always add that later on |
Hm something in that watch test is badly misbehaving and getting the CI stuck in a loop. Will need to look into that tomorrow, though nothing stands out at the moment. |
17cc1f3
to
4fe11a8
Compare
What kind of change does this PR introduce?
feature
Did you add tests for your changes?
Yes
Summary
This is something that's asked about fairly often and I figure it should become better supported for how low maintenance it is for us.
Any env vars prefixed with
PREACT_APP_
will now automatically be added toDefinePlugin
. This matches what CRA does and also (mostly) matches whatpreact-cli-plugin-env-vars
does. This is still a fairly popular plugin, getting ~1/10 of the downloads per week that preact-cli itself is.I added a note in the changeset to give credit for this functionality in the past. Hopefully that's appropriate; no code is actually shared.
.env
files in the user's project root are also now automatically consumed. Addeddotenv
for handling this.Does this PR introduce a breaking change?
Shouldn't be, no.