docusaurus/website/docs/using-plugins.md

81 lines
1.8 KiB
Markdown
Raw Normal View History

---
id: using-plugins
title: Plugins
sidebar_label: Introduction
---
Plugins are the building blocks of features in a Docusaurus 2 site. Each plugin handles its own individual feature. Plugins may work and be distributed as part of bundle via [presets](presets.md).
2019-07-03 02:12:22 -04:00
In this doc, we talk about how to use plugins with Docusaurus' official plugins. To learn about the design implementation and how to write your own plugins, check out [Advanced Guides: Plugins](advanced-plugins.md).
2019-07-03 02:12:22 -04:00
## Installing a plugin
A plugin is usually a npm package, so you install them like other npm packages using npm.
```bash
npm install --save docusaurus-plugin-name
```
Then you add it in your site's `docusaurus.config.js`'s `plugins` option:
```jsx {4}
// docusaurus.config.js
module.exports = {
// ...
plugins: ['@docusaurus/plugin-content-pages'],
};
```
Docusaurus can also load plugins from your local directory, you can do something like the following:
```jsx {6}
// docusaurus.config.js
const path = require('path');
module.exports = {
// ...
plugins: [path.resolve(__dirname, '/path/to/docusaurus-local-plugin')],
};
```
## Configuring plugins
2019-07-03 02:12:22 -04:00
For the most basic usage of plugins, you can provide just the plugin name or the absolute path to the plugin.
2019-07-03 02:12:22 -04:00
However, plugins can have options specified by wrapping the name and an options object in an array inside your config. This style is usually called `Babel Style`.
2019-07-03 02:12:22 -04:00
```js {5-10}
2019-07-03 02:12:22 -04:00
// docusaurus.config.js
module.exports = {
// ...
2019-07-03 02:12:22 -04:00
plugins: [
[
'@docusaurus/plugin-xxx',
{
/* options */
},
],
2019-07-03 02:12:22 -04:00
],
};
```
Example:
2019-07-03 02:12:22 -04:00
```js
// docusaurus.config.js
module.exports = {
plugins: [
// Basic usage.
'@docusaurus/plugin-google-analytics',
// With options object (babel style)
2019-07-03 02:12:22 -04:00
[
'@docusaurus/plugin-sitemap',
2019-07-03 02:12:22 -04:00
{
cacheTime: 600 * 1000,
2019-07-03 02:12:22 -04:00
},
],
],
};
```