--- sidebar_position: 2 --- # Extending infrastructure Docusaurus has some infrastructure like hot reloading, CLI, and swizzling, that can be extended by external plugins. ## `getPathsToWatch()` {/* #getPathsToWatch */} Specifies the paths to watch for plugins and themes. The paths are watched by the dev server so that the plugin lifecycles are reloaded when contents in the watched paths change. 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. Example: ```js title="docusaurus-plugin/src/index.js" import path from 'path'; export default function (context, options) { return { name: 'docusaurus-plugin', // highlight-start getPathsToWatch() { const contentPath = path.resolve(context.siteDir, options.path); return [`${contentPath}/**/*.{ts,tsx}`]; }, // highlight-end }; } ``` ## `extendCli(cli)` {/* #extendCli */} Register an extra command to enhance the CLI of Docusaurus. `cli` is a [Commander 15 `Command`](https://github.com/tj/commander.js/tree/v15.0.0) object. Example: ```js title="docusaurus-plugin/src/index.js" export default function (context, options) { return { name: 'docusaurus-plugin', // highlight-start extendCli(cli) { cli .command('roll') .description('Roll a random number between 1 and 1000') .action(() => { console.log(Math.floor(Math.random() * 1000 + 1)); }); }, // highlight-end }; } ``` ## `getThemePath()` {/* #getThemePath */} Returns the path to the directory where the theme components can be found. 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: ```js title="my-theme/src/index.js" export default function (context, options) { return { name: 'my-theme', // highlight-start getThemePath() { return './theme'; }, // highlight-end }; } ``` ## `getTypeScriptThemePath()` {/* #getTypeScriptThemePath */} Similar to `getThemePath()`, it should return the path to the directory where the source code of TypeScript theme components can be found. This path is purely for swizzling TypeScript theme components, and theme components under this path will **not** be resolved by the bundler. Therefore, it is not a replacement for `getThemePath()`. Typically, you can make the path returned by `getTypeScriptThemePath()` be your source directory, and make the path returned by `getThemePath()` be the compiled JavaScript output. :::tip For TypeScript theme authors: you are strongly advised to make your compiled output as human-readable as possible. Only strip type annotations and don't transpile any syntaxes, because Docusaurus transpiles them based on the targeted browser versions. You should also format these files with Prettier. Remember—JS files can and will be directly consumed by your users. ::: Example: ```js title="my-theme/src/index.js" export default function (context, options) { return { name: 'my-theme', // highlight-start getThemePath() { // Where compiled JavaScript output lives return '../lib/theme'; }, getTypeScriptThemePath() { // Where TypeScript source code lives return '../src/theme'; }, // highlight-end }; } ``` ## `getSwizzleConfig()` {/* #getSwizzleConfig */} **This is a static method, not attached to any plugin instance.** Export it from the theme module, or attach it to the plugin constructor function. Returns the swizzle config of the theme, declaring [how safe it is to swizzle](../../swizzling.mdx#what-is-safe-to-swizzle) each theme component: ```ts type SwizzleConfig = { components: { [componentName: string]: { actions: { eject: 'safe' | 'unsafe' | 'forbidden'; wrap: 'safe' | 'unsafe' | 'forbidden'; }; description?: string; }; }; }; ``` - `componentName`: the name of the theme component, relative to the theme path, such as `Footer` or `Admonition/Icon`. - `actions`: the safety status of each swizzle action. Actions not provided are `unsafe`. - `description`: a description of the component, displayed by `docusaurus swizzle --list`. Components not listed are `unsafe` to eject and to wrap. ```js title="my-theme/src/index.js" export default function (context, options) { return { name: 'my-theme', getThemePath() { return './theme'; }, }; } // highlight-start export function getSwizzleConfig() { return { components: { Footer: { actions: { eject: 'safe', wrap: 'safe', }, description: "The footer component of your site's layout", }, DocSidebar: { actions: { eject: 'unsafe', wrap: 'safe', }, description: 'The sidebar component on docs pages', }, 'prism-include-languages': { actions: { eject: 'safe', wrap: 'forbidden', // Not a component! }, }, }, }; } // highlight-end ``` ## `getSwizzleComponentList()` {/* #getSwizzleComponentList */} :::warning Deprecated Use [`getSwizzleConfig()`](#getSwizzleConfig) instead. ::: A static method returning the list of components that are safe to eject and to wrap. It is ignored when the theme provides `getSwizzleConfig()`.