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:
- Essential Gatsby includes functionality from the Gatsby Cache build plugin. If you already have the Gatsby Cache plugin installed on your Netlify site, you should remove it before installing this plugin.
- Essential Gatsby is not compatible with the Gatsby community plugin gatsby-plugin-netlify-cache.
- 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"
- From your project's base directory, add this plugin to
devDependencies
inpackage.json
.
# yarn add -D @netlify/plugin-gatsby npm install -D @netlify/plugin-gatsby
Read more about file-based plugin installation in our docs.
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:
- Make sure all your project's files are committed before running a build with the CLI
- Run any number of builds and deploys freely (i.e.
netlify build
,netlify deploy --build
,netlify deploy --prod
) - 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.
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.
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.