如何在没有 Gatsby 云的情况下使用 Gatsby 功能中的增量构建

how to use incremental build in Gatsby feature without Gatsby cloud

我在我的网站上使用 Gatsby 版本“2.32.13”,现在我想为我的网站使用 Gatsby 增量构建功能,但由于我的网站托管在 vercel 上,我不想使用 Gatsby Cloud。 那么有什么方法可以在不使用 Gatsby Cloud 的情况下实现这个 Gatsby Incremental Build 特性呢

它应该可以在任何 CI/CD 平台(Netlify、Vercel 等)上运行,即使在 Gatsby Cloud 中,实现起来也容易得多。您只需要通过添加环境变量 GATSBY_EXPERIMENTAL_PAGE_BUILD_ON_DATA_CHANGES 来调整您的部署命令。喜欢:

GATSBY_EXPERIMENTAL_PAGE_BUILD_ON_DATA_CHANGES=true gatsby build --log-pages

注意:--log-pages 标志将帮助您识别每个 运行

上的构建页面

为了确保 cross-environment 命令支持,我建议安装 cross-env 依赖项并相应地调整先前的命令:

cross-env GATSBY_EXPERIMENTAL_PAGE_BUILD_ON_DATA_CHANGES=true gatsby build --log-pages

对注意事项进行full (and official from Gatsby team)解释:

Conditional Page builds is an experimental feature that only works with data updates. Data updates in Gatsby means, data that comes from the GraphQL layer, in this case only page queries are supported. It can work with JSON updates when using gatsby-transformer-json and gatsby-source-filesystem.

Gatsby at this point in time is not going to invest in this feature and it will probably stay experimental without any development.

For more info about our roadmap see https://www.gatsbyjs.com/blog/announcing-unified-gatsby