-
-
Notifications
You must be signed in to change notification settings - Fork 26.8k
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
replace dotenv with dotenv-webpack? #6642
Comments
Just chiming in: it looks like you're using function featureIsEnabled(feature: string): boolean {
return !!feature && process.env["REACT_APP_FEATURE_"+feature.toUpperCase()] === "true";
} |
@heyimalex It took a while for me to get back to you but I finally found the time to do so. You were right, I did have some dynamic reads like that in the code. I've now removed them and replaced them with static calls, but I still get loads of full listings in my final build. ex.
--> original
Another:
--> original
These don't seem like very special cases to me? Any ideas of what is causing this? |
After looking into this further, I have noticed that only the places where an environment variable is used that has not been defined in the .env file get a full object listing like this. I do wonder why this is the "minified" version of the code, the compiler should be able to know that this value is undefined? |
I agree that that's a bug. I'll try and repro sometime soon, but if you want to dig in it looks like we use webpack's DefinePlugin. |
@Nickman87 I did a PR to try to fix this behavior but without feedback ... Can you test my branch to see it's still happening? |
Is this a bug report?
No
Description
We are using a .env file to make configuration changes easy between our different environments and it works great.
However, the way that
dotenv
works it not particularly interesting as it:In our codebase, we have a couple of variables and this block is inserted six times into our code:
In a project without create-react-app I've been using dotenv-webpack with great success. It effectively replaces your call to an environment variable with the value itself, minimizing code bloat.
I believe this would be a small change in the code, but I was wondering if there are reasons not to do this? If there is no reason not to switch it, I would like to work on a PR.
The text was updated successfully, but these errors were encountered: