Skip to content

Commit be746b9

Browse files
authored
www: move dotenv to gatsby-config so it can be used with GATSBY_SCREENSHOT_PLACEHOLDER (#9851)
1 parent e42d728 commit be746b9

File tree

4 files changed

+20
-22
lines changed

4 files changed

+20
-22
lines changed

docs/docs/programmatically-create-pages-from-data.md

+15-17
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ which is at the core of programmatically creating a page.
2323

2424
```javascript{17-25}:title=gatsby-node.js
2525
exports.createPages = ({ graphql, actions }) => {
26-
const { createPage } = actions;
26+
const { createPage } = actions
2727
return new Promise((resolve, reject) => {
2828
graphql(`
2929
{
@@ -45,12 +45,12 @@ exports.createPages = ({ graphql, actions }) => {
4545
context: {
4646
slug: node.fields.slug,
4747
},
48-
});
49-
});
50-
resolve();
51-
});
52-
});
53-
};
48+
})
49+
})
50+
resolve()
51+
})
52+
})
53+
}
5454
```
5555

5656
For each page we want to create we must specify the `path` for visiting that
@@ -66,23 +66,21 @@ that will be used to render the page. Here is an example of what the
6666
referenced template could look like:
6767

6868
```javascript:title=gatsby-node.js
69-
import React from 'react';
70-
import { graphql } from 'gatsby';
71-
import Layout from '../components/layout';
69+
import React from "react"
70+
import { graphql } from "gatsby"
71+
import Layout from "../components/layout"
7272

7373
export default ({ data }) => {
74-
const post = data.markdownRemark;
74+
const post = data.markdownRemark
7575
return (
7676
<Layout>
7777
<div>
78-
<h1>
79-
{post.frontmatter.title}
80-
</h1>
78+
<h1>{post.frontmatter.title}</h1>
8179
<div dangerouslySetInnerHTML={{ __html: post.html }} />
8280
</div>
8381
</Layout>
84-
);
85-
};
82+
)
83+
}
8684

8785
export const query = graphql`
8886
query($slug: String!) {
@@ -93,7 +91,7 @@ export const query = graphql`
9391
}
9492
}
9593
}
96-
`;
94+
`
9795
```
9896

9997
Notice that the `slug` value we specified in the `createPage` context is

packages/gatsby-transformer-screenshot/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ You can use placeholder image by setting `GATSBY_SCREENSHOT_PLACEHOLDER` environ
9494
GATSBY_SCREENSHOT_PLACEHOLDER=true gatsby develop
9595
```
9696

97-
or by adding it to `.env.development` file in root of your project:
97+
or by using [`dotenv`](https://www.gatsbyjs.org/docs/environment-variables/#server-side-nodejs) in your `gatsby-config.js` and adding `GATSBY_SCREENSHOT_PLACEHOLDER` to `.env.development` file in root of your project:
9898

9999
```shell:title=.env.development
100100
GATSBY_SCREENSHOT_PLACEHOLDER=true

www/gatsby-config.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
require(`dotenv`).config({
2+
path: `.env.${process.env.NODE_ENV}`,
3+
})
4+
15
module.exports = {
26
siteMetadata: {
37
title: `GatsbyJS`,

www/gatsby-node.js

-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ const moment = require(`moment`)
1313

1414
let ecosystemFeaturedItems
1515

16-
require(`dotenv`).config({
17-
path: `.env.${process.env.NODE_ENV}`,
18-
})
19-
2016
if (
2117
process.env.gatsby_executing_command === `build` &&
2218
!process.env.GITHUB_API_TOKEN

0 commit comments

Comments
 (0)