0
我使用createPages
基於一些JSON輸入,自動生成組件,這樣的蓋茨比組件:選擇createPages基於服務器端渲染或瀏覽器中呈現
exports.createPages = ({ graphql, boundActionCreators }) => {
const { createPage } = boundActionCreators
return new Promise((resolve, reject) => {
graphql(`
{
allPageJson{
edges {
node {
id
url
}
}
}
}
`).then(result => {
result.data.allPageJson.edges.map(({ node }) => {
createPage({
path: node.url,
component: path.resolve(`./src/templates/page.js`),
context: {
id: node.id,
},
})
})
resolve()
})
})
}
我所尋找的是一個參數或幫手告訴我,如果我目前在建模式或發展模式下運行,所以是這樣的:
exports.createPages = ({ isBuildMode }) => {
if (isBuildMode) {
console.log('looks like you ran gatsby build')
return
}
console.log('looks like you ran gatsby develop')
}