Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/facebook/docusaurus/llms.txt

Use this file to discover all available pages before exploring further.

The Docusaurus CLI provides a set of commands to develop, build, and deploy your documentation site. After bootstrapping a project, these commands are available through your package manager via the scripts defined in package.json.
package.json
{
  "scripts": {
    "docusaurus": "docusaurus",
    "start": "docusaurus start",
    "build": "docusaurus build",
    "swizzle": "docusaurus swizzle",
    "deploy": "docusaurus deploy",
    "clear": "docusaurus clear",
    "serve": "docusaurus serve",
    "write-translations": "docusaurus write-translations",
    "write-heading-ids": "docusaurus write-heading-ids"
  }
}

docusaurus start

Builds and serves a preview of your site locally using the Webpack Dev Server. Changes to your source files are reflected immediately through Hot Module Replacement.
docusaurus start [siteDir]
Some features such as anchor links behave differently in development. Use docusaurus build and docusaurus serve to preview production behavior exactly.

Options

NameDefaultDescription
-p, --port <port>3000Port for the dev server.
-h, --host <host>localhostHostname to bind. Use 0.0.0.0 to expose the server on all network interfaces.
-l, --locale <locale>Start the dev server for a specific site locale only.
--hot-onlyfalseDisable the full page refresh fallback when Hot Module Replacement fails.
--no-openfalsePrevent the browser from opening automatically on startup.
--config <config>[siteDir]/docusaurus.config.jsPath to a custom Docusaurus config file.
--poll [interval]falseUse file polling instead of filesystem watching for live reload. Accepts an optional interval in milliseconds.
--no-minifyfalseSkip JS/CSS bundle minification during the dev build.

Enabling HTTPS locally

1

Generate a local certificate

mkcert localhost
This creates localhost.pem and localhost-key.pem in the current directory.
2

Install the certificate in your trust store

mkcert -install
Restart your browser after this step.
3

Start the dev server with HTTPS

HTTPS=true SSL_CRT_FILE=localhost.pem SSL_KEY_FILE=localhost-key.pem yarn start
4

Open the site

Navigate to https://localhost:3000/.

Exposing the server over a network

When working inside a remote environment such as GitHub Codespaces, run the dev server on 0.0.0.0 to make it reachable from the forwarded port:
npm run start -- --host 0.0.0.0

docusaurus build

Compiles your site for production. Outputs static HTML, JS, and CSS to the build/ directory by default.
docusaurus build [siteDir]

Options

NameDefaultDescription
--devBuild in dev mode, enabling full React error messages.
--bundle-analyzerfalseOpen the webpack bundle analyzer to inspect output file sizes.
--out-dir <dir>buildOutput directory path, relative to the current workspace.
--config <config>[siteDir]/docusaurus.config.jsPath to a custom Docusaurus config file.
-l, --locale <locale...>all localesBuild only the specified locale(s). Pass the flag multiple times for multiple locales.
--no-minifyfalseSkip JS/CSS bundle minification.
CSS minification uses the advanced cssnano preset plus several PostCSS plugins by default. If you encounter broken styles after a build, set USE_SIMPLE_CSS_MINIFIER=true to fall back to the default cssnano preset. You can also skip HTML minification with SKIP_HTML_MINIFICATION=true.

docusaurus swizzle

Copies a theme component into your src/ directory so you can customize it. The interactive CLI guides you through selecting a theme, a component, and an action.
docusaurus swizzle [themeName] [componentName] [siteDir]
Example — eject the Footer component:
npm run swizzle @docusaurus/theme-classic Footer -- --eject

Options

NameDescription
themeNameName of the theme package to swizzle from (e.g., @docusaurus/theme-classic).
componentNameName of the component to swizzle (e.g., Footer).
-w, --wrapCreate a wrapper around the original component, rendering additional content before or after it.
-e, --ejectEject the full source of the component, allowing complete replacement.
-l, --listList all swizzleable components without prompting.
-t, --typescriptCopy the TypeScript variant of the component when available.
-j, --javascriptCopy the JavaScript variant of the component when available.
--dangerAllow swizzling of components marked as unsafe.
--config <config>Path to a custom Docusaurus config file.
Components marked as unsafe have a higher risk of breaking changes across Docusaurus versions due to internal refactoring. Use --danger with caution and test after each upgrade.
Wrap is safer. It keeps the original component intact and lets you render extra UI around it. Your wrapper re-uses the upstream component, so it is less likely to break on upgrades.Eject gives you full control but means you own the entire component source. You will need to manually reconcile changes when upgrading Docusaurus.

docusaurus deploy

Builds the site and deploys it to GitHub Pages. Reads organizationName, projectName, and optionally deploymentBranch from docusaurus.config.js.
docusaurus deploy [siteDir]

Options

NameDefaultDescription
-l, --locale <locale>all localesDeploy only the specified locale(s).
--out-dir <dir>buildOutput directory, relative to the current workspace.
--skip-buildfalseDeploy without rebuilding. Useful when using a custom build script.
--target-dir <dir>.Target subdirectory inside the deployment branch.
--config <config>[siteDir]/docusaurus.config.jsPath to a custom Docusaurus config file.
The deploy command uses SSH or HTTPS based on the USE_SSH environment variable. Set USE_SSH=true to deploy over SSH.

docusaurus serve

Serves the pre-built static site locally. Run docusaurus build first, or pass --build to build before serving.
docusaurus serve [siteDir]

Options

NameDefaultDescription
-p, --port <port>3000Port to serve on.
-h, --host <host>localhostHostname to bind.
--dir <dir>buildDirectory containing the built site, relative to the current workspace.
--buildfalseBuild the site before serving.
--no-openfalse locally, true in CIPrevent opening a browser window automatically.
--config <config>[siteDir]/docusaurus.config.jsPath to a custom Docusaurus config file.

docusaurus clear

Removes all generated build artifacts, caches, and temporary files from the .docusaurus/ and build/ directories.
docusaurus clear [siteDir]
Run docusaurus clear before reporting a bug, after upgrading Docusaurus, or whenever you experience unexpected build behavior. This command takes no additional flags.

docusaurus write-translations

Extracts all translatable strings from your site source code and writes JSON translation files to website/i18n/<defaultLocale>/ by default.
docusaurus write-translations [siteDir]

Options

NameDefaultDescription
-l, --locale <locale><defaultLocale>Target locale folder to write translation files into.
--overridefalseOverwrite existing translation messages. Commit or back up existing translations first.
--config <config>[siteDir]/docusaurus.config.jsPath to a custom Docusaurus config file.
--messagePrefix <prefix>""Prefix added to every new translation message to make untranslated strings visually distinct in the UI.

docusaurus write-heading-ids

Adds explicit heading IDs to your Markdown files. Explicit IDs let you control anchor links and prevent them from changing when you rename headings.
docusaurus write-heading-ids [siteDir] [files...]

Options

NameDefaultDescription
filesAll MD files used by pluginsSpecific files to process. Glob patterns are supported.
--syntax <syntax>classicID syntax to use: classic ({#id}) or mdx-comment ({/* #id */}).
--migratefalseConvert existing heading IDs to the target --syntax if they currently use a different format.
--overwritefalseRegenerate existing heading IDs from the heading text, replacing whatever is there.
--maintain-casefalsePreserve the original casing of heading text in the generated ID. By default all IDs are lowercased.
docusaurus write-heading-ids docs/ --syntax classic
# Produces: ## My Heading {#my-heading}

Build docs developers (and LLMs) love