gpt4 book ai didi

javascript - 根据服务器端渲染或浏览器渲染选择createPages gatsby组件

转载 作者:行者123 更新时间:2023-11-28 04:13:33 25 4
gpt4 key购买 nike

我使用 createPages 根据某些 JSON 输入自动生成组件,如下所示:

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')
}

最佳答案

process.env.NODE_ENV 是您最好的选择。很高兴讨论问题中的其他选项!

关于javascript - 根据服务器端渲染或浏览器渲染选择createPages gatsby组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46059325/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com