Using Plugins
The Docusaurus core doesn't provide any feature of its own. All features are delegated to individual plugins: the docs feature provided by the docs plugin; the blog feature provided by the blog plugin; or individual pages provided by the pages plugin. If there are no plugins installed, the site won't contain any routes.
You may not need to install common plugins one-by-one though: they can be distributed as a bundle in a preset. For most users, plugins are configured through the preset configuration.
We maintain a list of official plugins, but the community has also created some unofficial plugins. If you want to add any feature: autogenerating doc pages, executing custom scripts, integrating other services... be sure to check out the list: someone may have implemented it for you!
If you are feeling energetic, you can also read the plugin guide or plugin method references for how to make a plugin yourself.
Installing a plugin
A plugin is usually an npm package, so you install them like other npm packages using npm.
- npm
- Yarn
- pnpm
npm install --save docusaurus-plugin-name
yarn add docusaurus-plugin-name
pnpm add docusaurus-plugin-name
Then you add it in your site's docusaurus.config.js
's plugins
option:
export default {
// ...
plugins: ['@docusaurus/plugin-content-pages'],
};
Docusaurus can also load plugins from your local directory, with something like the following:
export default {
// ...
plugins: ['./src/plugins/docusaurus-local-plugin'],
};
Paths should be absolute or relative to the config file.
Configuring plugins
For the most basic usage of plugins, you can provide just the plugin name or the path to the plugin.
However, plugins can have options specified by wrapping the name and an options object in a two-member tuple inside your config. This style is usually called "Babel Style".
export default {
// ...
plugins: [
[
'@docusaurus/plugin-xxx',
{
/* options */
},
],
],
};
Example:
export default {
plugins: [
// Basic usage.
'@docusaurus/plugin-debug',
// With options object (babel style)
[
'@docusaurus/plugin-sitemap',
{
changefreq: 'weekly',
},
],
],
};
Multi-instance plugins and plugin IDs
All Docusaurus content plugins can support multiple plugin instances. For example, it may be useful to have multiple docs plugin instances or multiple blogs. It is required to assign a unique ID to each plugin instance, and by default, the plugin ID is default
.
export default {
plugins: [
[
'@docusaurus/plugin-content-docs',
{
id: 'docs-1',
// other options
},
],
[
'@docusaurus/plugin-content-docs',
{
id: 'docs-2',
// other options
},
],
],
};
At most one plugin instance can be the "default plugin instance", by omitting the id
attribute, or using id: 'default'
.
Using themes
Themes are loaded in the exact same way as plugins. From the consumer perspective, the themes
and plugins
entries are interchangeable when installing and configuring a plugin. The only nuance is that themes are loaded after plugins, and it's possible for a theme to override a plugin's default theme components.
The themes
and plugins
options lead to different shorthand resolutions, so if you want to take advantage of shorthands, be sure to use the right entry!
export default {
// ...
themes: ['@docusaurus/theme-classic', '@docusaurus/theme-live-codeblock'],
};
Using presets
Presets are bundles of plugins and themes. For example, instead of letting you register and configure @docusaurus/plugin-content-docs
, @docusaurus/plugin-content-blog
, etc. one after the other in the config file, we have @docusaurus/preset-classic
preset allows you to configure them in one centralized place.
@docusaurus/preset-classic
The classic preset is shipped by default to new Docusaurus websites created with create-docusaurus
. It contains the following themes and plugins:
@docusaurus/theme-classic
@docusaurus/theme-search-algolia
@docusaurus/plugin-content-docs
@docusaurus/plugin-content-blog
@docusaurus/plugin-content-pages
@docusaurus/plugin-debug
@docusaurus/plugin-google-gtag
@docusaurus/plugin-google-tag-manager
@docusaurus/plugin-google-analytics
(deprecated)@docusaurus/plugin-sitemap
The classic preset will relay each option entry to the respective plugin/theme.
export default {
presets: [
[
'@docusaurus/preset-classic',
{
// Debug defaults to true in dev, false in prod
debug: undefined,
// Will be passed to @docusaurus/theme-classic.
theme: {
customCss: ['./src/css/custom.css'],
},
// Will be passed to @docusaurus/plugin-content-docs (false to disable)
docs: {},
// Will be passed to @docusaurus/plugin-content-blog (false to disable)
blog: {},
// Will be passed to @docusaurus/plugin-content-pages (false to disable)
pages: {},
// Will be passed to @docusaurus/plugin-sitemap (false to disable)
sitemap: {},
// Will be passed to @docusaurus/plugin-google-gtag (only enabled when explicitly specified)
gtag: {},
// Will be passed to @docusaurus/plugin-google-tag-manager (only enabled when explicitly specified)
googleTagManager: {},
// DEPRECATED: Will be passed to @docusaurus/plugin-google-analytics (only enabled when explicitly specified)
googleAnalytics: {},
},
],
],
};
Installing presets
A preset is usually an npm package, so you install them like other npm packages using npm.
- npm
- Yarn
- pnpm
npm install --save @docusaurus/preset-classic
yarn add @docusaurus/preset-classic
pnpm add @docusaurus/preset-classic
Then, add it in your site's docusaurus.config.js
's presets
option:
export default {
// ...
presets: ['@docusaurus/preset-classic'],
};