-
-
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
Plugin to handle env vars a la CRA #341
Comments
Hey thank you for making this plugin. But I want to add my 2 cents here. Webpack will replace each process.env.PREACT_APP with the actual value. If you use this at many places, this could resolved in a huge bundle. This only make sense for NODE_ENV where replacing the value will help uglify removing dead code. If you're using this a lot, consider moving them to a normal js file with const |
@thangngoc89 I get what you mean! I would only recommend it for using things that need to be configured easily like Auth0 tokens, API urls, etc. It is very handy to use it in products like Netlify where you can define env vars for the build process. |
Is NODE_ENV or any other env (to identify production) available in a preact-cli project? If not, this seems like a no brainer plugin to use. |
NODE_ENV is supported by default, yes. It would be great to allow prefixed passthrough as noted above though. Just a note on the optimization side - multiple values will increase the textual size, but it'll actually be better for gzip! |
I've extracted another plugin from my created Preact SPA. It is a plugin to have support for environment variables a la CRA. Any env var prefixed with
PREACT_APP_
can be used in your code asconst secret = process.env.PREACT_APP_SUPER_SECRET
for example. It would be nice if it can be added to the wiki :) You can see the plugin here => https://github.com/robinvdvleuten/preact-cli-plugin-env-varsThe text was updated successfully, but these errors were encountered: