-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Allow for env files #1462
Allow for env files #1462
Conversation
Deploy preview ready! Built with commit 4dff300 |
Deploy preview ready! Built with commit 4dff300 |
Deploy preview ready! Built with commit 4dff300 |
Deploy preview ready! Built with commit 520b8d6 |
Deploy preview failed. Built with commit 520b8d6 https://app.netlify.com/sites/gatsbygram/deploys/5966675b6f4c504fd2c6eabd |
Deploy preview failed. Built with commit 520b8d6 https://app.netlify.com/sites/gatsbyjs/deploys/5966675b6f4c504fd2c6eabb |
This looks great! Could you start a docs page discussing using .env files? Really glad to see this pattern supported. Would be great too to get |
Sure thing. I could easily add From my understanding, the reason that create-react-app went the Am I missing something from Dan's comment here? I feel one could equally do Thoughts? |
I want Gatsby to work with other ways of setting environment variables other than .env files. So for .env, yeah you've done a great job there not overriding things so that's perhaps fine. But it'd be great to be able to run |
Ah, I see. Baby steps 👶 🍼 😬 Just added a docs file. Let me know what you think! |
No yeah, definitely don't feel like you have to solve everything in this PR :-) this is a great improvement! |
Fixed the docs typo |
Great PR! Thanks for helping improve Gatsby's abilities around env variables. That's something people have had to hand-code before. |
Usually dotenv is used to throw variables on
process.env
but in this case I'm just using theparse
method and adding those variables to webpack's DefinePlugin. This wayprocess.env
never gets altered.This also make sure not to overwrite
NODE_ENV
orPUBLIC_DIR
.To use, you'd just put an
.env.development
or.env.production
file in your root folder and those variables will be provided at dev/build time.Could fix #660