docs(v2): update docs about creating a new plugin #2963

This commit is contained in:
Colin Diesh 2020-06-19 09:32:36 -04:00 committed by GitHub
parent 56067e4add
commit 4aa77651d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -84,7 +84,14 @@ A plugin is a module which exports a function that takes two parameters and retu
The exported modules for plugins are called with two parameters: `context` and `options` and returns a JavaScript object with defining the [lifecycle APIs](./lifecycle-apis.md).
```js title="docusaurus.config.js"
For example if you have a reference to a local folder such as this in your
docusaurus.config.js:
plugins: [path.resolve(__dirname, 'my-plugin')],
Then in the folder `my-plugin` you can create an index.js such as this
```js title="index.js"
module.exports = function(context, options) {
// ...
return {
@ -96,6 +103,9 @@ module.exports = function(context, options) {
};
```
The `my-plugin` folder could also be a fully fledged package with it's own
package.json and a `src/index.js` file for example
#### `context`
`context` is plugin-agnostic and the same object will be passed into all plugins used for a Docusaurus website. The `context` object contains the following fields: