Giter Club home page Giter Club logo

Comments (3)

marcomelilli avatar marcomelilli commented on July 30, 2024

Hi! Thank you for the suggestion. Why do you think one file is better than two (.develop and .production)? I followed gatsby doc for best practices: https://www.gatsbyjs.org/docs/environment-variables/#client-side-javascript
I didn't commit these files because they are in the gitignore and I wanted to avoid that people will fork the project and they will commit their secrets in the repository

from gatsby-firebase-simple-auth.

ajhalili2006 avatar ajhalili2006 commented on July 30, 2024

Okay, I read the docs. So, did I need to add NODE_ENV variable to production, test, or staging if I want to just one .env file?

from gatsby-firebase-simple-auth.

marcomelilli avatar marcomelilli commented on July 30, 2024

In the gatsby-config.js you can see:

require("dotenv").config({
  path: `.env.${process.env.NODE_ENV}`,
})

And it works in this way with more .env files:

By default gatsby supports only 2 environments:

If you run gatsby develop, then you will be in the ‘development’ environment.
If you run gatsby build or gatsby serve, then you will be in the ‘production’ environment.

I don't know if it's possible use only a .env file, maybe you can change gatsby-config in this way:

require("dotenv").config({
  path: `.env`,
})

If you want add more custom environment (for example ".env.staging") you can't override NODE_ENV variable but you have to use another variable: https://www.gatsbyjs.org/docs/environment-variables/#additional-environments-staging-test-etc

const activeEnv =
  process.env.GATSBY_ACTIVE_ENV || process.env.NODE_ENV || "development"
require("dotenv").config({
  path: `.env.${activeEnv}`,
})

and build in this way from shell: GATSBY_ACTIVE_ENV=staging npm run develop

I understand you think one file is better, but this way is not bad too :)

from gatsby-firebase-simple-auth.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.