Extending infrastructure
Docusaurus has some infrastructure like hot reloading, CLI, and swizzling, that can be extended by external plugins.
getPathsToWatch()
Especifica os caminhos a serem observados por plug-ins e temas. Os caminhos são monitorados pelo servidor de desenvolvimento para que os ciclos de vida do plugin sejam recarregados quando o conteúdo dos caminhos monitorados muda. Note that the plugins and themes modules are initially called with context
and options
from Node, which you may use to find the necessary directory information about the site.
Use this for files that are consumed server-side, because theme files are automatically watched by Webpack dev server.
Exemplo:
import path from 'path';
export default function (context, options) {
return {
name: 'docusaurus-plugin',
getPathsToWatch() {
const contentPath = path.resolve(context.siteDir, options.path);
return [`${contentPath}/**/*.{ts,tsx}`];
},
};
}
extendCli(cli)
Registre um comando extra para melhorar a CLI do Docusaurus. cli
is a commander object.
The commander version matters! We use commander v5, and make sure you are referring to the right version documentation for available APIs.
Exemplo:
export default function (context, options) {
return {
name: 'docusaurus-plugin',
extendCli(cli) {
cli
.command('roll')
.description('Roll a random number between 1 and 1000')
.action(() => {
console.log(Math.floor(Math.random() * 1000 + 1));
});
},
};
}
getThemePath()
Retorna o caminho para o diretório onde os componentes do tema podem ser encontrados. When your users call swizzle
, getThemePath
is called and its returned path is used to find your theme components. Relative paths are resolved against the folder containing the entry point.
For example, your getThemePath
can be:
export default function (context, options) {
return {
name: 'my-theme',
getThemePath() {
return './theme';
},
};
}