--- description: Docusaurus provides a set of scripts to help you generate, serve, and deploy your website. --- # CLI Docusaurus provides a set of scripts to help you generate, serve, and deploy your website. Once your website is bootstrapped, the website source will contain the Docusaurus scripts that you can invoke with your package manager: ```json title="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 CLI commands {/* #docusaurus-cli-commands */} Below is a list of Docusaurus CLI commands and their usages: ### `docusaurus start [siteDir]` {/* #docusaurus-start-sitedir */} Builds and serves a preview of your site locally with [Webpack Dev Server](https://webpack.js.org/configuration/dev-server). #### Options {/* #options */} | Name | Default | Description | | --- | --- | --- | | `--port` | `3000` | Specifies the port of the dev server. | | `--host` | `localhost` | Specify a host to use. For example, if you want your server to be accessible externally, you can use `--host 0.0.0.0`. | | `--locale` | | Specify site locale to be used. | | `--hot-only` | `false` | Enables Hot Module Replacement without page refresh as a fallback in case of build failures. More information [here](https://webpack.js.org/configuration/dev-server/#devserverhotonly). | | `--no-open` | `false` | Do not open the page automatically in the browser. | | `--config` | `undefined` | Path to Docusaurus config file, default to `[siteDir]/docusaurus.config.js` | | `--poll [optionalIntervalMs]` | `false` | Use polling of files rather than watching for live reload as a fallback in environments where watching doesn't work. More information [here](https://webpack.js.org/configuration/watch/#watchoptionspoll). | | `--no-minify` | `false` | Build website without minimizing JS/CSS bundles. | | `--https` | `false` | Serve the dev site over HTTPS using a self-signed certificate. Implied when both `--ssl-cert` and `--ssl-key` are provided. | | `--ssl-cert` | `undefined` | Path to a TLS certificate file (implies HTTPS). | | `--ssl-key` | `undefined` | Path to a TLS private key file (implies HTTPS). | :::info Please note that some functionality (for example, anchor links) will not work in development. The functionality will work as expected in production. ::: :::info Development over network When forwarding port 3000 from a remote server or VM (e.g. GitHub Codespaces), you can run the dev server on `0.0.0.0` to make it listen on the local IP. ```bash npm2yarn npm run start -- --host 0.0.0.0 ``` ::: #### Enabling HTTPS {/* #enabling-https */} There are multiple ways to obtain a certificate. We will use [mkcert](https://github.com/FiloSottile/mkcert) as an example. 1. Run `mkcert localhost` to generate `localhost.pem` + `localhost-key.pem` 2. Run `mkcert -install` to install the cert in your trust store, and restart your browser 3. Start the app with the Docusaurus HTTPS CLI options: ```bash npm2yarn npm run start -- --ssl-cert localhost.pem --ssl-key localhost-key.pem ``` 4. Open `https://localhost:3000/` :::tip Self-signed certificate Use the `--https` option to serve the dev site over HTTPS with an automatically generated self-signed certificate: ```bash npm2yarn npm run start -- --https ``` ::: ### `docusaurus build [siteDir]` {/* #docusaurus-build-sitedir */} Compiles your site for production. #### Options {/* #options-1 */} | Name | Default | Description | | --- | --- | --- | | `--dev` | | Builds the website in dev mode, including full React error messages. | | `--out-dir` | `build` | The full path for the new output directory, relative to the current workspace. | | `--config` | `undefined` | Path to Docusaurus config file, default to `[siteDir]/docusaurus.config.js` | | `--locale` | | Build the site in the specified locale(s). If not specified, all known locales are built. | | `--no-minify` | `false` | Build website without minimizing JS/CSS bundles. | :::info CSS bundles are minified with [Lightning CSS](https://lightningcss.dev/), using your site's [Browserslist config](./browser-support.mdx) as targets. **Please [fill out an issue](https://github.com/meta/docusaurus/issues/new?labels=bug%2C+needs+triage&template=bug.md) if you experience CSS minification bugs.** You can skip the HTML minification with the environment variable `SKIP_HTML_MINIFICATION=true`. ::: ### `docusaurus swizzle [themeName] [componentName] [siteDir]` {/* #docusaurus-swizzle */} [Swizzle](./swizzling.mdx) a theme component to customize it. ```bash npm2yarn npm run swizzle [themeName] [componentName] [siteDir] # Example (leaving out the siteDir to indicate this directory) npm run swizzle @docusaurus/theme-classic Footer -- --eject ``` The swizzle CLI is interactive and will guide you through the whole [swizzle process](./swizzling.mdx). #### Options {/* #options-swizzle */} | Name | Description | | --- | --- | | `themeName` | The name of the theme to swizzle from. | | `componentName` | The name of the theme component to swizzle. | | `--list` | Display components available for swizzling | | `--eject` | [Eject](./swizzling.mdx#ejecting) the theme component | | `--wrap` | [Wrap](./swizzling.mdx#wrapping) the theme component | | `--danger` | Allow immediate swizzling of unsafe components | | `--typescript` | Swizzle the TypeScript variant component | | `--javascript` | Swizzle the JavaScript variant component | | `--config` | Path to docusaurus config file, default to `[siteDir]/docusaurus.config.js` | :::warning Unsafe components have a higher risk of breaking changes due to internal refactorings. ::: ### `docusaurus deploy [siteDir]` {/* #docusaurus-deploy-sitedir */} Deploys your site with [GitHub Pages](https://pages.github.com/). Check out the docs on [deployment](deployment/github-pages.mdx) for more details. #### Options {/* #options-3 */} | Name | Default | Description | | --- | --- | --- | | `--locale` | | Deploy the site in the specified locale(s). If not specified, all known locales are deployed. | | `--out-dir` | `build` | The full path for the new output directory, relative to the current workspace. | | `--skip-build` | `false` | Deploy website without building it. This may be useful when using a custom deploy script. | | `--target-dir` | `.` | Path to the target directory to deploy to. | | `--config` | `undefined` | Path to Docusaurus config file, default to `[siteDir]/docusaurus.config.js` | ### `docusaurus serve [siteDir]` {/* #docusaurus-serve-sitedir */} Serve your built website locally. | Name | Default | Description | | --- | --- | --- | | `--port` | `3000` | Use specified port | | `--dir` | `build` | The full path for the output directory, relative to the current workspace | | `--build` | `false` | Build website before serving | | `--config` | `undefined` | Path to Docusaurus config file, default to `[siteDir]/docusaurus.config.js` | | `--host` | `localhost` | Specify a host to use. For example, if you want your server to be accessible externally, you can use `--host 0.0.0.0`. | | `--no-open` | `false` locally, `true` in CI | Do not open a browser window to the server location. | #### 404 pages {/* #serve-404-pages */} `docusaurus serve` answers unknown paths with the nearest `404.html`, looking up the folders of the path. Each locale gets its own [localized 404 page](./i18n/i18n-tutorial.mdx#single-domain-deployment): `/fr/unknown` serves `/fr/404.html`. #### HTTP caching {/* #serve-http-caching */} `docusaurus serve` tells browsers how to cache each response with the [`Cache-Control`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Cache-Control) header: | Responses | `Cache-Control` | Browser behavior | | --- | --- | --- | | Files in `/assets/` | `public, max-age=31536000, immutable` | Reuses the file for one year, without asking the server. | | Everything else: pages, other static files, redirects, errors | `no-cache` | Asks the server before each reuse. The server answers `304 Not Modified` when the file content didn't change, using its [`ETag`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/ETag). | The bundler adds a content hash to the names of the files it emits in `/assets/` (JavaScript, CSS, images, fonts…): when the content of a file changes, its URL changes too. The other files keep their URLs from one build to the next. Revalidating them ensures you always see your latest build, and the redirects of your current [`baseUrl`](./api/docusaurus.config.js.mdx#baseUrl) and [`trailingSlash`](./api/docusaurus.config.js.mdx#trailingSlash) config, even after serving another site on the same port. The `/assets/` folders of the other locales of an [i18n site](./i18n/i18n-introduction.mdx), like `/fr/assets/`, are revalidated like the other files. :::warning Don't put files in an `assets` folder of your [static directories](./api/docusaurus.config.js.mdx#staticDirectories), like `static/assets/`. They are copied to `/assets/` without a content hash, so browsers can keep using an outdated version for one year. ::: ### `docusaurus clear [siteDir]` {/* #docusaurus-clear-sitedir */} Clear a Docusaurus site's generated assets, caches, build artifacts. We recommend running this command before reporting bugs, after upgrading versions, or anytime you have issues with your Docusaurus site. ### `docusaurus write-translations [siteDir]` {/* #docusaurus-write-translations-sitedir */} Write the JSON translation files that you will have to translate. By default, the files are written in `website/i18n//...`. | Name | Default | Description | | --- | --- | --- | | `--locale` | `` | Define which locale folder you want to write translations the JSON files in | | `--override` | `false` | Override existing translation messages | | `--config` | `undefined` | Path to Docusaurus config file, default to `[siteDir]/docusaurus.config.js` | | `--messagePrefix` | `''` | Allows adding a prefix to each translation message, to help you highlight untranslated strings | ### `docusaurus write-heading-ids [siteDir] [files]` {/* #docusaurus-write-heading-ids-sitedir */} Add [explicit heading IDs](./guides/markdown-features/markdown-features-toc.mdx#heading-ids) to the Markdown documents of your site. | Name | Default | Description | | --- | --- | --- | | `files` | All MD files used by plugins | The files that you want heading IDs to be written to. | | `--syntax` | Inferred | Heading ID syntax to use: `classic` (`{#id}`) or `mdx-comment` (`{/* #id */}`). By default, it uses `classic` for files compiled as CommonMark, and `mdx-comment` for files compiled as MDX, according to the [`markdown.format`](./api/docusaurus.config.js.mdx#markdown) config option. | | `--migrate` | `false` | Migrate existing heading IDs to the target `--syntax`, if they are using a different syntax. | | `--overwrite` | `false` | Overwrite existing heading IDs, re-generate them from the heading text. | | `--maintain-case` | `false` | Keep the headings' casing, otherwise make all lowercase. |