gatsby-plugin-utils

Gatsby utils that help creating plugins

MIT 321 个版本
安装
npm install gatsby-plugin-utils
yarn add gatsby-plugin-utils
pnpm add gatsby-plugin-utils
bun add gatsby-plugin-utils
README

gatsby-plugin-utils

Usage

npm install gatsby-plugin-utils

validateOptionsSchema

The validateOptionsSchema function verifies that the proper data types of options were passed into a plugin from the gatsby-config.js file. It is called internally by Gatsby to validate each plugin's options when a site is started.

Example

import { validateOptionsSchema } from "gatsby-plugin-utils"

await validateOptionsSchema(pluginName, pluginSchema, pluginOptions)

testPluginOptionsSchema

Utility to validate and test plugin options schemas. An example of a plugin options schema implementation can be found in the gatsby-node.js file of gatsby-plugin-google-analytics.

Example

// This is an example using Jest (https://jestjs.io/)
import { testPluginOptionsSchema } from "gatsby-plugin-utils"

it(`should partially validate one value of a schema`, async () => {
  const pluginSchema = ({ Joi }) =>
    Joi.object({
      someOtherValue: Joi.string(),
      toVerify: Joi.boolean(),
    })
  const expectedErrors = [`"toVerify" must be a boolean`]

  // Only the "toVerify" key of the schema will be verified in this test
  const { isValid, errors } = await testPluginOptionsSchema(pluginSchema, {
    toVerify: `abcd`,
  })

  expect(isValid).toBe(false)
  expect(errors).toEqual(expectedErrors)
})

isGatsbyNodeLifecycleSupported

Utility to be used by plugins to do runtime check against gatsby core package checking wether particular gatsby-node lifecycle API is supported. Useful for plugins to be able to support multiple gatsby core versions.

Example

const { isGatsbyNodeLifecycleSupported } = require(`gatsby-plugin-utils`)

// only use createSchemaCustomization lifecycle only when it's available.
if (isGatsbyNodeLifecycleSupported(`createSchemaCustomization`)) {
  exports.createSchemaCustomization = function createSchemaCustomization({
    actions,
  }) {
    // customize schema
  }
}

hasFeature

Feature detection is now part of Gatsby. As a plugin author you don't know what version of Gatsby a user is using. hasFeature allows you to check if the current version of Gatsby has a certain feature.

Here's a list of features: // TODO

Example

const { hasFeature } = require(`gatsby-plugin-utils`)

if (!hasFeature(`image-cdn`)) {
  // You can polyfill image-cdn here so older versions have support as well
}

Add ImageCDN support

Our new ImageCDN allows source plugins to lazily download and process images. if you're a plugin author please use this polyfill to add support for all Gatsby V4 versions.

For more information (see here)[https://gatsby.dev/img]

Example

const {
  addRemoteFilePolyfillInterface,
  polyfillImageServiceDevRoutes,
} = require(`gatsby-plugin-utils/pollyfill-remote-file`)

exports.createSchemaCustomization ({ actions, schema, store }) => {
  actions.createTypes([
    addRemoteFilePolyfillInterface(
      schema.buildObjectType({
        name: `PrefixAsset`,
        fields: {
          // your fields
        },
        interfaces: [`Node`, 'RemoteFile'],
      }),
      {
        schema,
        actions,
        store
      }
    )
  ]);
}

/** @type {import('gatsby').onCreateDevServer} */
exports.onCreateDevServer = ({ app, store }) => {
  polyfillImageServiceDevRoutes(app, store)
}
版本列表
4.17.0-react19.1 2025-11-26
4.17.0-react19.0 2025-11-26
4.17.0-next.0 2025-11-27
4.16.0 2026-01-26
4.16.0-next.0 2025-08-27
4.15.0 2025-08-27
4.15.0-next.0 2024-11-07
4.14.0 2024-11-06
4.14.0-next.2 2024-01-23
4.14.0-next.1 2024-01-04
4.14.0-next.0 2023-12-15
4.13.1 2024-01-23
4.13.0 2023-12-18
4.13.0-next.1 2023-11-16
4.13.0-next.0 2023-07-25
4.12.3 2023-10-26
4.12.2 2023-10-20
4.12.1 2023-10-09
4.12.0 2023-08-24
4.12.0-next.1 2023-07-03
4.12.0-next.0 2023-06-15
4.11.0 2023-06-15
4.11.0-next.1 2023-06-05
4.11.0-next.0 2023-05-16
4.10.0 2023-05-16
4.10.0-next.2 2023-05-03
4.10.0-next.1 2023-04-27
4.10.0-next.0 2023-04-18
4.9.0 2023-04-18
4.9.0-next.1 2023-04-06
4.9.0-next.0 2023-03-21
4.8.0 2023-03-21
4.8.0-next.0 2023-02-16
4.7.0 2023-02-21
4.7.0-next.0 2023-02-03
4.6.0 2023-02-07
4.6.0-next.1 2023-01-26
4.6.0-next.0 2023-01-19
4.5.0 2023-01-24
4.5.0-next.1 2023-01-17
4.5.0-next.0 2023-01-05
4.4.0 2023-01-10
4.4.0-next.2 2023-01-04
4.4.0-next.1 2022-12-14
4.4.0-next.0 2022-12-08
4.3.1 2022-12-14
4.3.0 2022-12-13
4.3.0-next.3 2022-12-07
4.3.0-next.2 2022-12-06
4.3.0-next.1 2022-12-01
4.3.0-next.0 2022-11-25
4.2.0 2022-11-25
4.2.0-next.0 2022-11-17
4.1.0 2022-11-22
4.1.0-next.0 2022-11-08
4.0.0-alpha-v5.26 2022-09-14
4.0.0-alpha-v5.25 2022-08-30
4.0.0-alpha-v5.24 2022-08-30
4.0.0-alpha-v5.16 2022-09-28
4.0.0 2022-11-08
4.0.0-next.4 2022-11-04
4.0.0-next.3 2022-10-25
4.0.0-next.2 2022-10-20
4.0.0-next.1 2022-10-18
4.0.0-next.0 2022-10-12
3.19.0 2022-12-07
3.19.0-next.0 2022-09-22
3.18.0 2022-09-27
3.18.0-next.2 2022-09-21
3.18.0-next.1 2022-09-21
3.18.0-next.0 2022-09-08
3.17.1 2022-09-22
3.17.0-alpha-v5.26 2022-09-04
3.17.0 2022-09-13
3.17.0-next.0 2022-08-25
3.16.0 2022-08-30
3.16.0-next.1 2022-08-15
3.16.0-next.0 2022-08-11
3.15.0 2022-08-16
3.15.0-next.2 2022-08-10
3.15.0-next.1 2022-08-04
3.15.0-next.0 2022-07-28
3.14.0 2022-08-02
3.14.0-next.2 2022-07-27
3.14.0-next.1 2022-07-25
3.14.0-next.0 2022-07-14
3.14.0-mdxv4-rc.65 2022-07-27
3.14.0-mdxv4-rc.60 2022-07-26
3.13.0 2022-07-19
3.13.0-next.1 2022-07-05
3.13.0-next.0 2022-06-30
3.12.1 2022-07-12
3.12.0 2022-07-05
3.12.0-next.1 2022-06-22
3.12.0-next.0 2022-06-16
3.12.0-mdxv4-rc.76 2022-07-25
3.12.0-mdxv4-rc.68 2022-07-07
3.11.0 2022-06-21
3.11.0-next.1 2022-06-13
3.11.0-next.0 2022-06-02
3.10.0 2022-06-07
3.10.0-next.1 2022-05-31
3.10.0-next.0 2022-05-20
3.9.1 2022-06-01
3.9.0 2022-05-24
3.9.0-next.2 2022-05-12
3.9.0-next.1 2022-05-09
3.9.0-next.0 2022-05-05
3.8.0 2022-05-10
3.8.0-next.3 2022-05-03
3.8.0-next.2 2022-04-29
3.8.0-next.1 2022-04-25
3.8.0-next.0 2022-04-21
3.7.0 2022-04-26
3.7.0-next.0 2022-04-07
3.6.1 2022-04-12
3.6.0 2022-04-12
3.6.0-next.3 2022-04-07
3.6.0-next.2 2022-04-01
3.6.0-next.1 2022-03-30
3.6.0-next.0 2022-03-24
3.5.1 2022-03-31
3.5.0-alpha-luda.30 2022-05-12
3.5.0 2022-03-29
3.5.0-next.3 2022-03-24
3.5.0-next.2 2022-03-21
3.5.0-next.1 2022-03-17
3.5.0-next.0 2022-03-14
3.4.2 2022-03-23
3.4.1 2022-03-18
3.4.0 2022-03-16
3.4.0-next.3 2022-03-08
3.4.0-next.2 2022-03-02
3.4.0-next.1 2022-03-01
3.4.0-next.0 2022-03-01
3.3.0 2022-03-01
3.3.0-next.0 2022-02-17
3.2.0 2022-02-22
3.2.0-next.1 2022-02-15
3.2.0-next.0 2022-02-07
3.1.0 2022-02-08
3.1.0-next.1 2022-02-02
3.1.0-next.0 2022-01-21
3.0.0 2022-01-25
3.0.0-next.0 2022-01-13
2.6.0-next.1 2022-01-13
2.6.0-next.0 2022-01-06
2.5.0 2022-01-11
2.5.0-next.1 2022-01-04
2.5.0-next.0 2021-12-09
2.4.0 2021-12-14
2.4.0-next.1 2021-12-09
2.4.0-next.0 2021-11-30
2.3.0 2021-12-01
2.3.0-next.0 2021-11-15
2.2.0 2021-11-16
2.2.0-next.2 2021-11-09
2.2.0-next.1 2021-11-08
2.2.0-next.0 2021-11-01
2.1.1 2021-11-09
2.1.0 2021-11-02
2.1.0-next.0 2021-10-20
2.0.0 2021-10-21
2.0.0-zz-next.8 2021-09-15
2.0.0-zz-next.3 2021-10-12
2.0.0-zz-next.2 2021-10-05
2.0.0-zz-next.1 2021-09-15
2.0.0-next.1 2021-09-14
2.0.0-next.0 2021-09-14
1.15.0 2022-12-07
1.14.0 2021-09-17
1.14.0-next.2 2021-09-07
1.14.0-next.1 2021-09-02
1.14.0-next.0 2021-08-27
1.13.0 2021-08-31
1.13.0-next.0 2021-08-12
1.12.0 2021-08-18
1.12.0-next.3 2021-08-09
1.12.0-next.2 2021-08-05
1.12.0-next.1 2021-08-05
1.12.0-next.0 2021-07-29
1.11.0 2021-08-04
1.11.0-next.0 2021-07-15
1.10.0 2021-07-20
1.10.0-next.1 2021-07-08
1.10.0-next.0 2021-07-01
1.9.0 2021-07-06
1.9.0-next.1 2021-06-28
1.9.0-next.0 2021-06-18
1.8.0 2021-06-22
1.8.0-next.1 2021-06-10
1.8.0-next.0 2021-06-03
1.7.1 2021-06-10
1.7.0 2021-06-08
1.7.0-next.2 2021-06-02
1.7.0-next.1 2021-05-31
1.7.0-next.0 2021-05-21
1.6.0 2021-05-25
1.6.0-next.0 2021-05-06
1.5.0 2021-05-11
1.5.0-next.0 2021-04-23
1.4.0 2021-04-27
1.4.0-next.0 2021-04-09
1.3.0 2021-04-13
1.3.0-next.1 2021-04-07
1.3.0-next.0 2021-03-25
1.2.0 2021-03-30
1.2.0-next.0 2021-03-11
1.1.0 2021-03-16
1.1.0-next.1 2021-02-26
1.1.0-next.0 2021-02-26
1.0.0 2021-03-02
1.0.0-v3rc.0 2021-02-26
1.0.0-next.1 2021-02-25
1.0.0-next.0 2021-02-05
0.10.0-next.0 2021-01-28
0.9.0 2021-02-02
0.9.0-next.0 2021-01-18
0.8.0 2021-01-19
0.8.0-next.1 2021-01-12
0.8.0-next.0 2020-12-29
0.7.0 2021-01-05
0.7.0-next.1 2020-12-17
0.7.0-next.0 2020-12-10
0.6.0 2020-12-15
0.6.0-next.0 2020-11-26
0.5.0 2020-12-02
0.5.0-next.0 2020-11-18
0.4.0 2020-11-19
0.4.0-next.0 2020-11-10
0.3.0 2020-11-12
0.3.0-next.1 2020-11-10
0.3.0-next.0 2020-11-03
0.2.40 2020-10-28
0.2.39 2020-10-22
0.2.38 2020-10-21
0.2.37 2020-10-20
0.2.36 2020-10-19
0.2.35 2020-10-19
0.2.34 2020-10-16
0.2.33 2020-10-16
0.2.32 2020-10-15
0.2.31 2020-10-14
0.2.30 2020-10-13
0.2.29 2020-10-13
0.2.28 2020-10-12
0.2.27 2020-10-07
0.2.27-qod.21 2020-10-21
0.2.27-qod.20 2020-10-21
0.2.27-qod.19 2020-10-20
0.2.26 2020-10-06