Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.

Commit 00bc864

Browse files
author
BSKY
authored
Merge pull request #244 from tkt989/docs/creating-a-local-plugin
Translate docs/creating-a-local-plugin
2 parents 4b35915 + c6f7a67 commit 00bc864

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed
Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
2-
title: Creating a Local Plugin
2+
titie: ローカルプラグインの作成
33
---
44

5-
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.
5+
もしプラグインを特定の用途で使うときや、簡単なやりかたでプラグインを開発したいときは、ローカルに定義されたプラグインを使うことで作成および管理が便利になります。
66

7-
## Project structure for a local plugin
7+
## ローカルプラグインのプロジェクト構成
88

9-
Place the code in the `plugins` folder in the root of your project like this:
9+
このように、コードをプロジェクトルートの `plugins` フォルダーの中に配置します。
1010

1111
```text
1212
/my-gatsby-site
@@ -17,9 +17,9 @@ Place the code in the `plugins` folder in the root of your project like this:
1717
└── package.json
1818
```
1919

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.
20+
また、プラグインは自動的に検知されないので、`gatsby-config.js` に追加する必要があります。すでに、設定ファイルに含まれているサードパーティー Gatsby プラグインと同じように追加できます。
2121

22-
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:
22+
`gatsby develop` を実行するとき、プラグインを検知するため、プラグインのルートフォルダーの名前は `gatsby-config.js` で使用しているもの(`package.json` で使用している名前**ではありません**)と同じにする必要があります。上記の構成では、プラグインを読み込む正しい方法は以下のようになります。
2323

2424
```javascript:title=gatsby-config.js
2525
module.exports = {
@@ -30,49 +30,47 @@ module.exports = {
3030
}
3131
```
3232

33-
Then the plugin can begin to hook into Gatsby through [Node](/docs/node-apis/) and [SSR](/docs/ssr-apis/) APIs.
33+
その後、プラグインは [Node](/docs/node-apis/) [SSR](/docs/ssr-apis/) API を介して Gatsby に接続されます。
3434

35-
## Developing a local plugin that is outside your project
35+
## プロジェクト外部のローカルプラグインを開発する
3636

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.
37+
プラグインを動作させたりテストするために、必ずプロジェクトに含めないといけないわけではありません。もしプラグインをサイトから[分離](/docs/glossary#decoupled)させたいなら、以下の方法が使えます。これはプラグインをパッケージとして公開したいときや、コミュニティーが作成したプラグインをフォークしたものをテスト、開発するときに便利です。
3838

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):
39+
40+
`gatsby new`[プラグインのスターター](https://github.com/gatsbyjs/gatsby/tree/master/starters/gatsby-starter-plugin)を使用すれば、素早くプロジェクト外部のプラグインの開発を始めることができます:
4041

4142
```shell
4243
gatsby new gatsby-plugin-foo https://github.com/gatsbyjs/gatsby-starter-plugin
4344
```
4445

45-
### Using `require.resolve` and a filepath
46+
### `require.resolve` とファイルパスを使う
4647

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`.
48+
`plugins` フォルダーがローカルプラグインを参照する唯一の方法ではありません。ほかに `gatsby-config.js` ファイルで、`require` を使い直接パス(`gatsby-config.js` からの相対パス)を指定して、プラグインを含めることができます。
4849

4950
```javascript:title=gatsby-config.js
5051
module.exports = {
5152
plugins: [
5253
`gatsby-plugin-react-helmet`,
5354
// highlight-start
5455
{
55-
// including a plugin from outside the plugins folder needs the path to it
56+
// plugins フォルダ外のプラグインを使うためにパスを指定
5657
resolve: require.resolve(`../path/to/gatsby-local-plugin`),
5758
},
5859
// highlight-end
5960
],
6061
}
6162
```
6263

63-
### Using `npm link` or `yarn link`
64+
### `npm link` または `yarn link` を使う
6465

65-
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.
66+
あなたのマシン内の別の場所にあるパッケージを参照するときは、[`npm link`](https://docs.npmjs.com/cli/link.html) [`yarn link`](https://yarnpkg.com/lang/en/docs/cli/link/) が使えます。
6667

67-
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` を実行すると、パッケージへのシンボリックリンクが作られます。
6869

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).
70+
これは、Gatsby テーマ開発の yarn ワークスペースを作成するときと同じ工程(テーマを開発する際に推奨される方法)です。[テーマ作成ガイド](/tutorial/buidling-a-theme/#set-up-yarn-workspaces) でサイトを設定する方法を読むことができます。
7071

71-
**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).
72+
**ヒント**`require.resolve` `npm link` を使って、plugins フォルダーからローカルプラグインを使う例として、[こちらのサンプルリポジトリ](https://github.com/gatsbyjs/gatsby/tree/master/examples/using-multiple-local-plugins)をご覧ください。
7273

73-
## Compilation and processing with Babel
74+
## Babel を使ってコンパイルする
7475

75-
Like all `gatsby-*` files, the code is not processed by Babel. If you want
76-
to use JavaScript syntax which isn't supported by your version of Node.js, you
77-
can place the files in a `src` subfolder and build them to the plugin folder
78-
root.
76+
`gatsby-*` ファイルと同じように、Babel によるコンパイルは行われません。もし使用している Node.js のバージョンではサポートされていない JavaScript 構文を使いたいときは、ファイルを `src` サブフォルダーに置き、プラグインフォルダーのルートへビルドされるようにしてください。

0 commit comments

Comments
 (0)