You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Documentation for multiple environments
Updating documentation to provide guidance on environment support beyond development and production
* add gatsby develop environment command
`NODE_ENV` is a reserved environment variable in Gatsby as it is needed by the build system to make key optimizations when compiling React and other modules. For this reason it is advised to make use of a secondary environment variable for additional environment support.
78
+
79
+
For instance. If you would like to add a staging environment with a custom Google Analytics Tracking ID. You can add `.env.staging` at the root of your project with the following modification to your `gatsby-config.js`
80
+
81
+
### Example
82
+
83
+
```shell
84
+
# .env.staging
85
+
GATSBY_GA_TRACKING_ID="UA-1234567890"
86
+
```
87
+
88
+
```javascript
89
+
// gatsby-config.js
90
+
91
+
let activeEnv =process.env.ACTIVE_ENV;
92
+
93
+
if (!activeEnv) {
94
+
activeEnv ='development';
95
+
}
96
+
97
+
require('dotenv').config({
98
+
path:`.env.${activeEnv}`
99
+
});
100
+
101
+
module.exports= {
102
+
siteMetadata: {
103
+
title:'Gatsby Default Starter'
104
+
},
105
+
plugins: [
106
+
{
107
+
resolve:`gatsby-plugin-google-analytics`,
108
+
options: {
109
+
trackingId:process.env.GATSBY_GA_TRACKING_ID,
110
+
// Puts tracking script in the head instead of the body
0 commit comments