I recently configured Gatsby Cloud for my Gatsby app, the github integration and previews seemed very useful. I was previously using circleci to do a production build and deploy to aws. I did not previously have a staging site where i deployed a development build.
I added my production env vars to the Build section of the environment variables settings. Then I added my development env vars to the Preview section. No matter what i configure in gatsby-config.js the build process that GC uses automatically defaults to production on my PR builds. There is no info on this in the docs unfortunately.
gatsby-config.js:
I see "development" logged for activeEnv during the PR Build process, which is what I expect. dotenv technically should be loading .env.development, but it doesnt end up with the development GRAPHQL_URL url. process.env.GRAPHQL_URL always logs out as the value in .env.production
I added my production env vars to the Build section of the environment variables settings. Then I added my development env vars to the Preview section. No matter what i configure in gatsby-config.js the build process that GC uses automatically defaults to production on my PR builds. There is no info on this in the docs unfortunately.
gatsby-config.js:
Code:
let activeEnv = process.env.GATSBY_IS_PREVIEW ? "development" : process.env.NODE_ENV || "development";
require("dotenv").config({
path: `.env.${activeEnv}`,
});
console.log(`** Build Env: '${activeEnv}'`);
console.log("** BACKEND URL:", process.env.GRAPHQL_URL);