@builder.io/gatsby

中文文档
4.0.0发布于 2024/01/12MIT近 30 天下载 6526

A plugin for using Builder.io with Gatsby

原始使用文档
文档目录5 节
  1. Install
  2. How to use
  3. Using your components in the editor
  4. How to Query
  5. Learn more

@builder.io/gatsby

Plugin for integrating Builder.io to allow drag and drop page building with Gatsby. It puts the Builder.io schema under an allBuilderModels field of the Gatsby GraphQL query, If a templates map is passed as option, this plugin will create gatsby pages dynamically for each page entry in builder.io on the path specified.

example

Install

npm install @builder.io/gatsby

How to use

Make a free account over at Builder.io and grab your public API key from your organization page and:

// In your gatsby-config.js
const path = require('path');
module.exports = {
  plugins: [
    {
      resolve: '@builder.io/gatsby',
      options: {
        // public API Key
        publicAPIKey: 'MY_PUBLIC_API_KEY',
        // OPTIONAL
        // Set this to `true` to rely on our cached content. Default value is `false`, always fetching the newest content from Builder.
        useCache: false,
        // OPTIONAL
        // mapping model names to template files, the plugin will create a page for each entry of the model at its specified url
        templates: {
          // `page` can be any model of choice, camelCased
          page: path.resolve('templates/my-page.tsx'),
        },
        // OPTIONAL
        mapEntryToContext: async ({ entry, graphql }) => {
          const result = await graphql('....');
          return {
            property: entry.data.property,
            anotherProperty: entry.data.whatever,
            dataFromQuery: result.data
            /* ... */
          };
        },
        // OPTIONAL
        // to resolve a single entry to multiple, for e.g in localization
        resolveDynamicEntries: async (entries) => {
          const entriesToBuild = []
          for entry of entries {
            if (entry.data.myprop.isDynamic){
               entriesToBuild.push(await myEntryResolver(entry))
            }
            else {
               entriesToBuild.push(entry)
            }
          }
          return entriesToBuild;
        },
      },
    },
  ],
};

Then start building pages in Builder.io, hit publish, and they will be incluced in your Gatsby site on each new build!

For a more advanced example and a starter check out gatsby-starter-builder

Using your components in the editor

See this design systems example for lots of examples using your deisgn system + custom components

👉Tip: want to limit page building to only your components? Try components only mode

Register a component

import { Builder } from '@builder.io/react';

class SimpleText extends React.Component {
  render() {
    return <h1>{this.props.text}</h1>;
  }
}

Builder.registerComponent(SimpleText, {
  name: 'Simple Text',
  inputs: [{ name: 'text', type: 'string' }],
});

How to Query

For an up-to-date complete examples check out the Gatsby + Builder.io starter

{
  allBuilderModels {
    myPageModel(options: { cachebust: true }) {
      content
    }
  }
}

Learn more

版本与发布记录

@builder.io/gatsby 共发布 65 个版本,首次发布于 2020/02/26;过去 12 个月发布了 0 个版本。

版本发布日期距今
4.0.0latest2024/01/122 年前
3.0.32022/12/143 年前
3.0.22022/09/104 年前
3.0.2-1dev2022/09/084 年前
3.0.2-02022/09/084 年前
3.0.12022/03/014 年前

关于 @builder.io/gatsby 的常见问题

@builder.io/gatsby 是什么?

A plugin for using Builder.io with Gatsby

如何安装 @builder.io/gatsby?

在项目目录运行 npm install @builder.io/gatsby,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:gatsby(>= 4)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@builder.io/gatsby 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/builder.io__gatsby 是否存在。

@builder.io/gatsby 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=14.15.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@builder.io/gatsby 可以商用吗?

@builder.io/gatsby 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@builder.io/gatsby 的下载量有多少?

根据 npm 官方下载统计,@builder.io/gatsby 在 2026/10/09 – 2026/11/07 这 30 天内被下载 6,526 次,日均约 218 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@builder.io/gatsby 还在维护吗?

最新版本 4.0.0 发布于 2024/01/12(2 年前);至今共发布 65 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/02/26。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。