You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: add starter for plugins with new plugin recipes (#22258)
* add starter for plugins
* add recipes for using the plugin starter and installing a plugin
* Apply suggestions from code review
Co-Authored-By: LB <[email protected]>
Co-authored-by: LB <[email protected]>
Co-authored-by: gatsbybot <[email protected]>
Copy file name to clipboardExpand all lines: docs/docs/creating-a-local-plugin.md
+6
Original file line number
Diff line number
Diff line change
@@ -36,6 +36,12 @@ Then the plugin can begin to hook into Gatsby through [Node](/docs/node-apis/) a
36
36
37
37
Your plugin doesn't have to be in your project in order to be tested or worked on. If you'd like to [decouple](/docs/glossary#decoupled) your plugin from your site you can follow one of the methods described below. This is a useful thing to do if you want to publish the plugin as its own package, or test/develop a forked version of a community authored plugin.
38
38
39
+
To get started developing a plugin outside of your site's root folder, you can quickly generate one using `gatsby new` with the [starter for plugins](https://github.com/gatsbyjs/gatsby/tree/master/starters/gatsby-starter-plugin):
40
+
41
+
```shell
42
+
gatsby new gatsby-plugin-foo https://github.com/gatsbyjs/gatsby-starter-plugin
43
+
```
44
+
39
45
### Using `require.resolve` and a filepath
40
46
41
47
Including a `plugins` folder is not the only way to reference a local plugin. Alternatively, you can include a plugin in your `gatsby-config.js` file by directly referencing its path (relative to the `gatsby-config.js` file) with `require`.
Copy file name to clipboardExpand all lines: docs/docs/recipes.md
+14-7
Original file line number
Diff line number
Diff line change
@@ -55,21 +55,28 @@ There are so many ways to add styles to your website; Gatsby supports almost eve
55
55
-[Using Google Fonts](/docs/recipes/styling-css#using-google-fonts)
56
56
-[Using Font Awesome](/docs/recipes/styling-css#using-fontawesome)
57
57
58
-
## [3. Working with starters](/docs/recipes/working-with-starters)
58
+
## [3. Working with plugins](/docs/recipes/working-with-plugins)
59
+
60
+
[Plugins](/docs/plugins/) are Node.js packages that implement Gatsby APIs that are maintained officially, or by the community.
61
+
62
+
-[Using a plugin](/docs/recipes/working-with-plugins#using-a-plugin)
63
+
-[Creating a new plugin using a plugin starter](/docs/recipes/working-with-plugins#creating-a-new-plugin-using-a-plugin-starter)
64
+
65
+
## [4. Working with starters](/docs/recipes/working-with-starters)
59
66
60
67
[Starters](/docs/starters/) are boilerplate Gatsby sites maintained officially, or by the community.
61
68
62
69
-[Using a starter](/docs/recipes/working-with-starters#using-a-starter)
63
70
64
-
## [4. Working with themes](/docs/recipes/working-with-themes)
71
+
## [5. Working with themes](/docs/recipes/working-with-themes)
65
72
66
73
A Gatsby theme lets you centralize the look-and-feel of your site. You can seamlessly update a theme, compose themes together, and even swap out one compatible theme for another.
67
74
68
75
-[Creating a new site using a theme](/docs/recipes/working-with-themes#creating-a-new-site-using-a-theme)
69
76
-[Creating a new site using a theme starter](/docs/recipes/working-with-themes#creating-a-new-site-using-a-theme-starter)
70
77
-[Building a new theme](/docs/recipes/working-with-themes#building-a-new-theme)
Pull data from multiple locations, like the filesystem or database, into your Gatsby site.
75
82
@@ -80,7 +87,7 @@ Pull data from multiple locations, like the filesystem or database, into your Ga
80
87
-[Pulling data from an external source and creating pages without GraphQL](/docs/recipes/sourcing-data#pulling-data-from-an-external-source-and-creating-pages-without-graphql)
81
88
-[Sourcing content from Drupal](/docs/recipes/sourcing-data#sourcing-content-from-drupal)
-[Querying data client-side with fetch](/docs/recipes/querying-data#querying-data-client-side-with-fetch)
96
103
97
-
## [7. Working with images](/docs/recipes/working-with-images)
104
+
## [8. Working with images](/docs/recipes/working-with-images)
98
105
99
106
Access images as static resources, or automate the process of optimizing them through powerful plugins.
100
107
@@ -103,14 +110,14 @@ Access images as static resources, or automate the process of optimizing them th
103
110
-[Optimizing and querying local images with gatsby-image](/docs/recipes/working-with-images#optimizing-and-querying-local-images-with-gatsby-image)
104
111
-[Optimizing and querying images in post frontmatter with gatsby-image](/docs/recipes/working-with-images#optimizing-and-querying-images-in-post-frontmatter-with-gatsby-image)
Transforming data in Gatsby is plugin-driven. Transformer plugins take data fetched using source plugins, and process it into something more usable (e.g. JSON into JavaScript objects, and more).
109
116
110
117
-[Transforming Markdown into HTML](/docs/recipes/transforming-data#transforming-markdown-into-html)
111
118
-[Transforming images into grayscale using GraphQL](/docs/recipes/transforming-data#transforming-images-into-grayscale-using-graphql)
112
119
113
-
## [9. Deploying your site](/docs/recipes/deploying-your-site)
120
+
## [10. Deploying your site](/docs/recipes/deploying-your-site)
114
121
115
122
Showtime. Once you are happy with your site, you are ready to go live with it!
A [Gatsby plugin](/docs/what-is-a-plugin/) abstracts Gatsby APIs into an installable package. This means that modular chunks of Gatsby functionality aren’t directly written into your project, but rather versioned, centrally managed, and installed as a dependency. You can add external data, transform data, add third-party services (e.g. Google Analytics, Stripe), and more.
7
+
8
+
## Using a plugin
9
+
10
+
Found a plugin you'd like to use in your project? Awesome! You can configure it for use by following the steps below. This recipe uses the [`gatsby-source-filesystem` plugin](/plugins/gatsby-source-filesystem) as an example.
11
+
12
+
> If you'd like to take a look at available plugins, check out the [plugin library](/plugins).
13
+
14
+
### Prerequisites
15
+
16
+
- An existing [Gatsby site](/docs/quick-start/) with a `gatsby-config.js` file
17
+
18
+
### Directions
19
+
20
+
1. Install the `gatsby-source-filesystem` plugin by running the following command:
21
+
22
+
```shell
23
+
npm install gatsby-source-filesystem
24
+
```
25
+
26
+
2. Add the plugin to your `gatsby.config.js`, and set any options it needs, the filesystem source plugin takes a `name` and `path` as options:
27
+
28
+
```javascript:title=gatsby-config.js
29
+
module.exports= {
30
+
plugins: [
31
+
// highlight-start
32
+
{
33
+
resolve:`gatsby-source-filesystem`,
34
+
options: {
35
+
name:`images`,
36
+
path:`${__dirname}/src/images`,
37
+
},
38
+
},
39
+
// highlight-end
40
+
],
41
+
}
42
+
```
43
+
44
+
_The instructions found in the README of the plugin you're using can you help you determine specifics about what configurations (if any) it requires. For this example to have an effect in your own site, you would need to create the `src/images` folder and place files inside of it._
45
+
46
+
3. Run `gatsby develop`, your plugin should run as your site builds.
47
+
48
+
### Additional resources
49
+
50
+
- Learn more about configuring options or using default options in the [Using a Plugin in Your Site](/docs/using-a-plugin-in-your-site/) guide.
51
+
- See an example Gatsby site using this configuration in [the repo for the default Gatsby starter](https://github.com/gatsbyjs/gatsby-starter-default/blob/master/gatsby-config.js).
52
+
53
+
## Creating a new plugin using a plugin starter
54
+
55
+
If you want to create your own plugin you can get started with the Gatsby plugin starter.
56
+
57
+
### Prerequisites
58
+
59
+
- An existing [Gatsby site](/docs/quick-start/) with a `gatsby-config.js` file
60
+
61
+
### Directions
62
+
63
+
1._Outside_ of your Gatsby site, generate a new plugin based on the starter using the `gatsby new` command:
64
+
65
+
```shell
66
+
gatsby new my-plugin https://github.com/gatsbyjs/gatsby-starter-plugin
67
+
```
68
+
69
+
The directory structure should look something like this:
70
+
71
+
```
72
+
gatsby-site
73
+
└── gatsby-config.js
74
+
└── src
75
+
├── components
76
+
└── pages
77
+
my-plugin
78
+
├── gatsby-browser.js
79
+
├── gatsby-node.js
80
+
├── gatsby-ssr.js
81
+
├── index.js
82
+
└── package.json
83
+
```
84
+
85
+
2. Add the plugin to your site's `gatsby-config.js`, linking it to your local plugin's root folder with `require.resolve`. The path (or name of the plugin) should be to the directory name you used when generating the plugin:
86
+
87
+
```javascript:title=gatsby-site/gatsby-config.js
88
+
module.exports= {
89
+
plugins: [
90
+
require.resolve(`../my-plugin), // highlight-line
91
+
],
92
+
}
93
+
```
94
+
95
+
3. Run `gatsby develop`. To verify the plugin starter loaded correctly in your site it will log a message to the console saying it "Loaded" before the `onPreInit` step finishes.
96
+
97
+
4. Now you can implement [browser](/docs/browser-apis/), [server-side rendering](/docs/ssr-apis/), or [node APIs](/docs/node-apis/) and your site will run them each time it loads your plugin!
98
+
99
+
### Additional resources
100
+
101
+
- Read about creating and loading your own plugins in development in the [Creating a Local Plugin](/docs/creating-a-local-plugin/) guide
Copy file name to clipboardExpand all lines: docs/docs/recipes/working-with-themes.md
+7-7
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ A [Gatsby theme](/docs/themes/what-are-gatsby-themes) abstracts Gatsby configura
9
9
10
10
Found a theme you'd like to use on your project? Awesome! You can configure it for use by following the steps below.
11
11
12
-
> If you'd like to take a look at more theme options, check out [list of themes](https://www.npmjs.com/search?q=gatsby-theme).
12
+
> If you'd like to take a look at more theme options, check out this [list of themes](/plugins?=gatsby-theme).
13
13
14
14
### Prerequisites
15
15
@@ -32,11 +32,11 @@ cd {your-project-name}
32
32
npm install gatsby-theme-blog
33
33
```
34
34
35
-
3. Add theme to `gatsby.config.js`
35
+
3. Add theme to `gatsby-config.js`
36
36
37
37
Follow the instructions found in the README of the theme you're using to determine what configuration it requires.
38
38
39
-
```shell
39
+
```javascript:title=gatsby-config.js
40
40
module.exports= {
41
41
plugins: [
42
42
{
@@ -55,15 +55,15 @@ module.exports = {
55
55
}
56
56
```
57
57
58
-
4. Run `gatsby develop`, the theme should be available at `http://localhost:8000/{basePath}`
58
+
4. Run `gatsby develop`, the theme should now be running on your site. In this case with the blog theme configured with the `basePath` to "/blog", it should be available at `http://localhost:8000/blog`.
59
59
60
-
> To learn how to further customize a theme, check out the available paths on [Gatsby-theme-blog Documentation](https://www.npmjs.com/package/gatsby-theme-blog).
60
+
> To learn how to further customize a theme, check out the available paths on [Gatsby-theme-blog Documentation](/packages/gatsby-theme-blog/#theme-options).
61
61
62
62
### Additional resources
63
63
64
-
- To learn how to further customize a theme, check out the docs on [Gatsby theme shadowing.](https://www.gatsbyjs.org/docs/themes/shadowing/)
64
+
- To learn how to further customize a theme, check out the docs on [Gatsby theme shadowing.](/docs/themes/shadowing/)
65
65
66
-
- You can also [use multiple themes](https://www.gatsbyjs.org/docs/themes/using-multiple-gatsby-themes/) on a project.
66
+
- You can also [use multiple themes](/docs/themes/using-multiple-gatsby-themes/) on a project.
0 commit comments