New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reorganizing plugin docs #13261
Reorganizing plugin docs #13261
Changes from all commits
46dd4f9
e0f5e8a
f90641d
64114b9
928b552
813ef44
90c10d3
4695639
673f61d
4856848
f250996
57a6f74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
Title: Creating a Local Plugin | ||
--- | ||
|
||
If a plugin is only relevant to your specific use-case, or if you’re developing a plugin and want a simpler workflow, a locally defined plugin is a convenient way to create and manage your plugin code. | ||
|
||
Place the code in the `plugins` folder in the root of your project like this: | ||
|
||
``` | ||
plugins | ||
└── my-own-plugin | ||
└── package.json | ||
``` | ||
|
||
**NOTE:** You still need to add the plugin to your `gatsby-config.js`. There is no auto-detection of local plugins. | ||
|
||
**NOTE:** For the plugin to be discovered, the plugin's root folder name is the value that needs to be referenced in order to load it (_not_ its _name_ in its package.json file). For example, in the above structure, the correct way to load the plugin is: | ||
|
||
```javascript:title=gatsby-config.js | ||
module.exports = { | ||
plugins: ["my-own-plugin"], | ||
} | ||
``` | ||
|
||
Like all `gatsby-*` files, the code is not processed by Babel. If you want | ||
to use JavaScript syntax which isn't supported by your version of Node.js, you | ||
can place the files in a `src` subfolder and build them to the plugin folder | ||
root. | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
title: Creating Plugins | ||
--- | ||
|
||
You may be looking to build and perhaps publish a plugin that doesn't exist yet, or you may just be curious to know more about the anatomy of a Gatsby plugin (file structure, etc). | ||
|
||
## Core concepts | ||
|
||
- Each Gatsby plugin can be created as an npm package or as a [local plugin](#local-plugins) | ||
- A `package.json` is required | ||
- Plugins implement the Gatsby APIs for [Node](/docs/node-apis/), [server-side rendering](/docs/ssr-apis/), and the [browser](/docs/browser-apis/) | ||
|
||
This section of the docs includes the following guides: | ||
|
||
[[guidelist]] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
title: Files Gatsby Looks for in a Plugin | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This page is fantastic! |
||
--- | ||
|
||
## What files does Gatsby look for in a plugin? | ||
|
||
All files are optional unless specifically marked as required. | ||
|
||
- `package.json` — [required] this can be an empty object (`{}`) for local plugins | ||
- `name` is used to identify the plugin when it mutates Gatsby’s GraphQL data structure | ||
- if `name` isn’t set, the folder name for the plugin is used | ||
- `version` is used to manage the cache — if it changes, the cache is cleared | ||
- if `version` isn’t set, an MD5 hash of the `gatsby-*` file contents is used to invalidate the cache | ||
- omitting the `version` field is recommended for local plugins | ||
- `keywords` is used to make your plugin discoverable | ||
- plugins published on the npm registry should have `gatsby` and `gatsby-plugin` in the `keywords` field to be added to the [Plugin Library](/packages/) | ||
- `gatsby-browser.js` — usage details are in the [browser API reference](/docs/browser-apis/) | ||
- `gatsby-node.js` — usage details are in the [Node API reference](/docs/node-apis/) | ||
- `gatsby-ssr.js` — usage details are in the [SSR API reference](/docs/ssr-apis/) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
title: Maintaining a Plugin | ||
--- | ||
|
||
This is a stub article meant to be filled with tips on how to maintain a Gatsby plugin once you've published it as an npm package. | ||
|
||
Topics to be covered: | ||
|
||
- yarn workspaces can solve yarn link inconsistencies | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jlengstorf or @DSchau want to add any more details here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would think this could have some technical bits and some social OSS bits, including: Technical
Social
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
title: Naming a Plugin | ||
--- | ||
|
||
## Plugin title naming conventions | ||
|
||
There are four standard plugin naming conventions for Gatsby: | ||
|
||
- **`gatsby-source-*`** — a source plugin loads data from a given source (e.g. WordPress, MongoDB, the file system). Use this plugin type if you are connecting a new source of data to Gatsby. | ||
- Example: [`gatsby-source-contentful`](https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-contentful) | ||
- Docs: [creating a source plugin](/docs/creating-a-source-plugin/) | ||
- **`gatsby-transformer-*`** — a transformer plugin converts data from one format (e.g. CSV, YAML) to a JavaScript object. Use this naming convention if your plugin will be transforming data from one format to another. | ||
- Example: [`gatsby-transformer-yaml`](https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-transformer-yaml) | ||
- Docs: [creating a transformer plugin](/docs/creating-a-transformer-plugin/) | ||
- **`gatsby-[plugin-name]-*`** — if a plugin is a plugin for another plugin 😅, it should be prefixed with the name of the plugin it extends (e.g. if it adds emoji to the output of `gatsby-transformer-remark`, call it `gatsby-remark-add-emoji`). Use this naming convention whenever your plugin will be included as a plugin in the `options` object of another plugin. | ||
- Example: [`gatsby-remark-images`](https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-remark-images) | ||
- **`gatsby-plugin-*`** — this is the most general plugin type. Use this naming convention if your plugin doesn’t meet the requirements of any other plugin types. | ||
- Example: [`gatsby-plugin-sharp`](https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-sharp) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
--- | ||
title: Using a Plugin in Your Site | ||
--- | ||
|
||
Gatsby plugins are Node.js packages, so you can install them like other packages in node using NPM. | ||
|
||
For example, `gatsby-transformer-json` is a package which adds support for JSON files to the Gatsby data layer. | ||
|
||
To install it, in the root of your site you run: | ||
|
||
```shell | ||
npm install --save gatsby-transformer-json | ||
``` | ||
|
||
Then in your site's `gatsby-config.js` you add `gatsby-transformer-json` to the plugins array like: | ||
|
||
```javascript:title=gatsby-config.js | ||
module.exports = { | ||
plugins: [`gatsby-transformer-json`], | ||
} | ||
``` | ||
|
||
Plugins can take options. For example: | ||
|
||
```javascript:title=gatsby-config.js | ||
module.exports = { | ||
plugins: [ | ||
// Shortcut for adding plugins without options. | ||
"gatsby-plugin-react-helmet", | ||
{ | ||
// Standard plugin with options example | ||
resolve: `gatsby-source-filesystem`, | ||
options: { | ||
path: `${__dirname}/src/data/`, | ||
name: "data", | ||
}, | ||
}, | ||
{ | ||
resolve: "gatsby-plugin-offline", | ||
// Blank options, equivalent to string-only plugin | ||
options: { | ||
plugins: [], | ||
}, | ||
}, | ||
{ | ||
resolve: `gatsby-transformer-remark`, | ||
options: { | ||
// plugins inside plugins | ||
plugins: [`gatsby-remark-smartypants`], | ||
}, | ||
}, | ||
], | ||
} | ||
``` | ||
|
||
Note that plugin options will be stringified by Gatsby, so they cannot be functions. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
title: "What is a Plugin?" | ||
--- | ||
|
||
Gatsby plugins are Node.js packages that implement Gatsby APIs. For larger, more complex sites, plugins let you modularize your site customizations into site-specific plugins. | ||
|
||
One of the best ways to add functionality to Gatsby is through our plugin system. Gatsby is designed to be extensible, which means plugins are able to extend and modify just about everything Gatsby does. | ||
|
||
Of the many possibilities, plugins can: | ||
|
||
- add external data or content (e.g. your CMS, static files, a REST API) to your Gatsby GraphQL data | ||
- transform data from other formats (e.g. Markdown, YAML, CSV) to JSON objects | ||
- add third-party services (e.g. Google Analytics, Instagram) to your site | ||
- do anything you can dream up! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
title: What You Don't Need Plugins For | ||
--- | ||
|
||
Most third-party functionality you want to add to your website will follow standard JavaScript and React.js patterns for importing packages and composing UIs. These do not require a Gatsby plugin! | ||
|
||
Some examples: | ||
|
||
- Importing JavaScript packages that provide general functionality, such as `lodash` or `axios` | ||
- Using React components or component libraries you want to include in your UI, such as `Ant Design`, `Material UI`, or the typeahead from your component library. | ||
- Integrating visualization libraries, such as `Highcharts` or `d3`. | ||
|
||
As a general rule, you may use _any_ npm package you might use without Gatsby, with Gatsby. What plugins offer is a prepackaged integration into the core Gatsby APIs to save you time and energy, with minimal configuration. In the case of `Styled Components`, you could manually render the `Provider` component near the root of your application, or you could just use `gatsby-plugin-styled-components` which takes care of this step for you in addition to any other difficulties you may run into configuring Styled Components to work with server side rendering. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we could also mention this package as an option. @DSchau @KyleAMathews would that make sense in this context? https://www.gatsbyjs.org/packages/gatsby-plugin-compile-es6-packages/