They are called environment variables. They are intended to store sensitive data such as tokens, identifiers, etc, and they shouldn't be pushed in your repository, so you should ignore them (in your
By default, Gatsby creates 2 environments without noticing you, one for each compilation method:
gatsby develop: uses
gatsby build: uses
Note: you can change this behavior if needed to add your own environments using
NODE_ENV custom commands.
So, to pass your data to your
gatsby-config.js you just need to create two files (
.env.production) at the root of your project. Then, add the following snippet at the top of your
dotenv is already a dependency of Gatsby so you don't need to install it again
This will tell Gatsby where to take the environment variables.
You just remain to populate both environment files. Look for the credentials in Contentful and add them in the files using the sane naming than you've set in your
Keep also in mind that when dealing with Azure, Netlify, AWS, or similar CI/CD tools, you'll need to provide to the server the same environment files to avoid a code-breaking when pushing the changes.