Plugin Method References
Esta seção está em progresso. Anchor links or even URLs are not guaranteed to be stable.
Plugin APIs are shared by themes and plugins—themes are loaded just like plugins.
Plugin module
Every plugin is imported as a module. The module is expected to have the following members:
- A default export: the constructor function for the plugin.
- Named exports: the static methods called before plugins are initialized.
Plugin constructor
The plugin module's default export is a constructor function with the signature (context: LoadContext, options: PluginOptions) => Plugin | Promise<Plugin>
.
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:
type LoadContext = {
siteDir: string;
generatedFilesDir: string;
siteConfig: DocusaurusConfig;
outDir: string;
baseUrl: string;
};
options
options
are the second optional parameter when the plugins are used. options
are plugin-specific and are specified by users when they use them in docusaurus.config.js
. If there's a validateOptions
function exported, the options
will be validated and normalized beforehand.
Alternatively, if a preset contains the plugin, the preset will then be in charge of passing the correct options into the plugin. It is up to the individual plugin to define what options it takes.