What's the proper way of setting environment variables in netlify? I would like to be able to set different values for the variables depending on the environment.
Pseudo code:
let host;
if (process.env.GATSBY_CUSTOM_CONTEXT === 'production') {
host = process.env.PRODUCTION_HOST
} else if (process.env.GATSBY_CUSTOM_CONTEXT === 'development') {
host = process.env.DEVELOPMENT_HOST
}
I have tried passing env variable thru CLI, like GATSBY_CUSTOM_CONTEXT=production gatsby build and I also tried using same command with cross-env.
About me
My question in a little more detail
What's the proper way of setting environment variables in netlify? I would like to be able to set different values for the variables depending on the environment.
Pseudo code:
I have tried passing env variable thru CLI, like
GATSBY_CUSTOM_CONTEXT=production gatsby build
and I also tried using same command withcross-env
.My other attempt used
netlify.toml
:All of these options worked with
netlify dev
locally, but in productionGATSBY_CUSTOM_CONTEXT
is alwaysundefined
.