-
Notifications
You must be signed in to change notification settings - Fork 8
/
gatsby-node.js
46 lines (42 loc) · 938 Bytes
/
gatsby-node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const path = require("path")
exports.onCreateWebpackConfig = ({ actions, stage }) => {
if (stage === "develop-html" || stage === "build-html") {
actions.setWebpackConfig({
resolve: {
mainFields: ["main"],
},
})
} else {
actions.setWebpackConfig({
resolve: {
mainFields: ["browser", "module", "main"],
},
})
}
}
exports.createPages = ({ graphql, actions }) => {
const { createPage } = actions
const bookTemplate = path.resolve("src/templates/bookTemplate.js")
return graphql(`
{
allBook {
edges {
node {
id
}
}
}
}
`).then(result => {
if (result.errors) {
throw result.errors
}
result.data.allBook.edges.forEach(book => {
createPage({
path: `/book/${book.node.id}`,
component: bookTemplate,
context: { bookId: book.node.id },
})
})
})
}