Migrate to Netlify Today

Netlify announces the next evolution of Gatsby Cloud. Learn more

ContactSign Up
Community Plugin
View plugin on GitHub

gatsby-adapter-netlify

Gatsby adapter for Netlify.

This adapter enables following features on Netlify:

This adapter is part of Gatsby’s zero-configuration deployments feature and will be installed automatically on Netlify. You can add gatsby-adapter-netlify to your dependencies and gatsby-config to have more robust installs and to be able to change its options.

Installation

npm install gatsby-adapter-netlify

Usage

Add gatsby-adapter-netlify to your gatsby-config and configure the adapter option.

const adapter = require("gatsby-adapter-netlify")

module.exports = {
  adapter: adapter({
    excludeDatastoreFromEngineFunction: false,
    imageCDN: false,
  }),
}

Options

excludeDatastoreFromEngineFunction

(optional, default: false)

If true, Gatsby will not include the LMDB datastore in the serverless functions used for SSR/DSG. Instead, it will upload the datastore to Netlify’s CDN and download it on first load of the functions.

You can also enable this option by setting GATSBY_EXCLUDE_DATASTORE_FROM_BUNDLE=true environment variable (useful when using zero-configuration deployments)

imageCDN

(optional, default: false)

If true instead of downloading and processing images at build time, it defers processing until request time using Netlify Image CDN. This can greatly improve build times for sites with remote images, such as those that use a CMS.

You can also enable this option by setting NETLIFY_IMAGE_CDN=true environment variable (useful when using zero-configuration deployments)

You will need additional configuration in your netlify.toml configuration file to allow external domains for images. See Netlify Image CDN Remote Path docs for more information.

Exact Remote Path regular expressions to use will depend on CMS you use and possibly your configuration of it.

  • gatsby-source-contentful:

    [images]
    remote_images = [
      # <your-contentful-space-id> is specified in the `spaceId` option for the
      # gatsby-source-contentful plugin in your gatsby-config file.
      "https://images.ctfassets.net/<your-contentful-space-id>/.*"
    ]
  • gatsby-source-drupal:

    [images]
    remote_images = [
      # <your-drupal-base-url> is speciafied in the `baseUrl` option for the
      # gatsby-source-drupal plugin in your gatsby-config file.
      "<your-drupal-base-url>/.*"
    ]
  • gatsby-source-wordpress:

    [images]
    remote_images = [
      # <your-wordpress-url> is specified in the `url` option for the
      # gatsby-source-wordpress plugin in your gatsby-config file.
      # There is no need to include `/graphql in the path here`
      "<your-wordpress-url>/.*"
    ]

Above examples are the most likely ones to be needed. However if you configure your CMS to host assets on different domain or path, you might need to adjust the patterns accordingly.

If you are using recent versions of Contentful, Drupal or Wordpress source plugins, Gatsby and Netlify Adapter will automatically detect missing Remote Path patterns and will warn you about it and provide the required patterns to add to your configuration.

© 2023 Gatsby, Inc.