2019-04-28 23:20:24 -04:00
---
id: using-plugins
2019-10-26 04:10:48 -04:00
title: Plugins
sidebar_label: Introduction
2019-04-28 23:20:24 -04:00
---
2019-10-26 04:10:48 -04:00
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
2019-07-26 01:00:40 -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
2019-07-26 01:00:40 -04:00
## Installing a plugin
2019-10-26 04:10:48 -04:00
A plugin is usually a npm package, so you install them like other npm packages using npm.
2019-07-26 01:00:40 -04:00
```bash
npm install --save docusaurus-plugin-name
```
Then you add it in your site's `docusaurus.config.js` 's `plugins` option:
2019-10-29 02:59:24 -04:00
```jsx {4}
2019-07-26 01:00:40 -04:00
// docusaurus.config.js
module.exports = {
2019-10-29 02:59:24 -04:00
// ...
2019-07-26 01:00:40 -04:00
plugins: ['@docusaurus/plugin-content-pages'],
};
```
Docusaurus can also load plugins from your local directory, you can do something like the following:
2019-10-29 02:59:24 -04:00
```jsx {6}
2019-07-26 01:00:40 -04:00
// docusaurus.config.js
const path = require('path');
module.exports = {
2019-10-29 02:59:24 -04:00
// ...
2019-07-26 01:00:40 -04:00
plugins: [path.resolve(__dirname, '/path/to/docusaurus-local-plugin')],
};
```
## Configuring plugins
2019-07-03 02:12:22 -04:00
2019-10-26 04:10:48 -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
2019-10-26 04:10:48 -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
2019-10-29 02:59:24 -04:00
```js {5-10}
2019-07-03 02:12:22 -04:00
// docusaurus.config.js
module.exports = {
2019-10-29 02:59:24 -04:00
// ...
2019-07-03 02:12:22 -04:00
plugins: [
2019-07-08 02:14:49 -04:00
[
2019-10-26 04:10:48 -04:00
'@docusaurus/plugin-xxx',
2019-07-08 02:14:49 -04:00
{
2019-10-26 04:10:48 -04:00
/* options */
2019-07-08 02:14:49 -04:00
},
],
2019-07-03 02:12:22 -04:00
],
};
```
2019-10-26 04:10:48 -04:00
Example:
2019-07-03 02:12:22 -04:00
```js
// docusaurus.config.js
module.exports = {
2019-10-26 04:10:48 -04:00
plugins: [
// Basic usage.
'@docusaurus/plugin-google-analytics',
// With options object (babel style)
2019-07-03 02:12:22 -04:00
[
2019-10-26 04:10:48 -04:00
'@docusaurus/plugin-sitemap',
2019-07-03 02:12:22 -04:00
{
2019-10-26 04:10:48 -04:00
cacheTime: 600 * 1000,
2019-07-03 02:12:22 -04:00
},
],
],
};
```