Skip to content

cmanou/netlify-plugin-gatsby

 
 

Netlify Build plugin Gatsby – Run Gatsby seamlessly on Netlify

Essential Gatsby Plugin

This build plugin is a utility for supporting Gatsby on Netlify. To support build caching and Gatsby functions on Netlify, you will need to install this plugin for your app.

Note:

Table of Contents

Installation and Configuration

Manual Installation

  1. Create a netlify.toml in the root of your project. Your file should include the plugins section below:
[build] command = "npm run build" publish = "public/" [[plugins]] package = "@netlify/plugin-gatsby"
  1. From your project's base directory, add this plugin to devDependencies in package.json.
# yarn add -D @netlify/plugin-gatsby npm install -D @netlify/plugin-gatsby

Read more about file-based plugin installation in our docs.

CLI Usage

If you'd like to build and deploy your project using the Netlify CLI, we recommend this workflow to manage git tracking plugin-generated files:

  1. Make sure all your project's files are committed before running a build with the CLI
  2. Run any number of builds and deploys freely (i.e. netlify build, netlify deploy --build, netlify deploy --prod)
  3. Run git stash --include-unstaged to easily ignore plugin-generated files

It's important to note that the CLI may mix your project's source code and plugin-generated files; this is why we recommend committing all project source files before running CLI builds.

Using Gatsby Functions

This plugin will convert all Gatsby Functions in the project to run as Netlify functions. This should be invisible: you can write the Gatsby Functions in the same way as you usually would. The API is the same, and if you use this plugin then it will deploy to Netlify functions without needing any extra configuration.

When the site is built, this plugin will create a wrapper Netlify function in /netlify/functions/gatsby, and then deploy that alongside the Gatsby functions. If you run this locally with the Netlify CLI, you will see it create these files. It will add an entry to your .gitignore to ignore the /netlify/functions/gatsby directory.

Local development

When developing Gatsby Functions it is usually easier to use the built-in gatsby develop functions server. However if you want to try the Netlify functions wrapper it will run via netlify dev. However you should be sure to run netlify build first, so that the wrappers are generated and the functions copied across.

About

A build plugin to integrate Gatsby seamlessly with Netlify

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 99.0%
  • Shell 1.0%