Skip to content
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

Closed
robinvdvleuten opened this issue Aug 24, 2017 · 4 comments
Closed

Plugin to handle env vars a la CRA #341

robinvdvleuten opened this issue Aug 24, 2017 · 4 comments
Labels

Comments

@robinvdvleuten
Copy link

robinvdvleuten commented Aug 24, 2017

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 as const 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-vars

@thangngoc89
Copy link
Collaborator

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

@robinvdvleuten
Copy link
Author

@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.

@DevanB
Copy link

DevanB commented Oct 20, 2017

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.

@thangngoc89 @robinvdvleuten

@developit
Copy link
Member

developit commented Dec 25, 2017

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants