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
{{ message }}
This repository was archived by the owner on Jan 20, 2025. It is now read-only.
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:
9
+
このように、コードをプロジェクトルートの `plugins`フォルダーの中に配置します。
10
10
11
11
```text
12
12
/my-gatsby-site
@@ -17,9 +17,9 @@ Place the code in the `plugins` folder in the root of your project like this:
17
17
└── package.json
18
18
```
19
19
20
-
The plugin also needs to be added to your `gatsby-config.js`, because there is no auto-detection of plugins. It can be added alongside any other 3rd party Gatsby plugins already included in your config.
For the plugin to be discovered when you run `gatsby develop`, the plugin's root folder name needs to match the name used in the `gatsby-config.js`(_not_ the _name_ it goes by in your `package.json`file). For example, in the above structure, the correct way to load the plugin is:
## Developing a local plugin that is outside your project
35
+
## プロジェクト外部のローカルプラグインを開発する
36
36
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.
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):
gatsby new gatsby-plugin-foo https://github.com/gatsbyjs/gatsby-starter-plugin
43
44
```
44
45
45
-
### Using `require.resolve`and a filepath
46
+
### `require.resolve`とファイルパスを使う
46
47
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`.
You can use [`npm link`](https://docs.npmjs.com/cli/link.html)or[`yarn link`](https://yarnpkg.com/lang/en/docs/cli/link/)to reference a package from another location on your machine.
By running`npm link ../path/to/my-plugin`in the root of your Gatsby site, your computer will create a symlink to your package.
68
+
Gatsby サイトのルートで`npm link ../path/to/my-plugin`を実行すると、パッケージへのシンボリックリンクが作られます。
68
69
69
-
This is a similar process to setting up yarn workspaces for development with Gatsby themes (which is the recommended approach for developing themes). You can read how to setup a site in this manner in the [Building a Theme guide](/tutorial/building-a-theme/#set-up-yarn-workspaces).
**Note**: See an example of using a local plugin from the plugins folder, with `require.resolve`, and`npm link`in [this example repository](https://github.com/gatsbyjs/gatsby/tree/master/examples/using-multiple-local-plugins).
0 commit comments