2019-04-28 23:20:24 -04:00
---
2022-05-28 07:07:45 -04:00
description: Docusaurus provides a set of scripts to help you generate, serve, and deploy your website.
2019-04-28 23:20:24 -04:00
---
2021-03-23 13:07:21 -04:00
# CLI
2019-11-17 08:44:02 -05:00
Docusaurus provides a set of scripts to help you generate, serve, and deploy your website.
2019-04-28 23:20:24 -04:00
2020-04-14 11:26:55 -04:00
Once your website is bootstrapped, the website source will contain the Docusaurus scripts that you can invoke with your package manager:
2019-04-28 23:20:24 -04:00
2020-03-28 13:08:50 -04:00
```json title="package.json"
2019-05-17 07:01:34 -04:00
{
// ...
"scripts": {
2021-03-05 13:36:14 -05:00
"docusaurus": "docusaurus",
2019-05-17 07:01:34 -04:00
"start": "docusaurus start",
"build": "docusaurus build",
"swizzle": "docusaurus swizzle",
2020-09-28 10:33:35 -04:00
"deploy": "docusaurus deploy",
2021-03-05 13:36:14 -05:00
"clear": "docusaurus clear",
"serve": "docusaurus serve",
"write-translations": "docusaurus write-translations",
"write-heading-ids": "docusaurus write-heading-ids"
2019-05-17 07:01:34 -04:00
}
}
```
2021-03-19 06:00:41 -04:00
## Docusaurus CLI commands {#docusaurus-cli-commands}
2019-05-17 07:01:34 -04:00
Below is a list of Docusaurus CLI commands and their usages:
2021-03-19 06:00:41 -04:00
### `docusaurus start [siteDir]` {#docusaurus-start-sitedir}
2019-05-17 07:01:34 -04:00
2020-04-14 11:26:55 -04:00
Builds and serves a preview of your site locally with [Webpack Dev Server](https://webpack.js.org/configuration/dev-server).
2019-05-17 07:01:34 -04:00
2021-03-19 06:00:41 -04:00
#### Options {#options}
2019-05-17 07:01:34 -04:00
2020-04-14 11:26:55 -04:00
| Name | Default | Description |
2019-11-17 08:44:02 -05:00
| --- | --- | --- |
2020-05-17 23:37:53 -04:00
| `--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`. |
2021-12-27 06:34:04 -05:00
| `--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). |
2019-11-17 08:44:02 -05:00
| `--no-open` | `false` | Do not open automatically the page in the browser. |
2022-06-15 01:04:33 -04:00
| `--config` | `undefined` | Path to Docusaurus config file, default to `[siteDir]/docusaurus.config.js` |
2020-10-21 13:16:53 -04:00
| `--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). |
2022-05-20 00:50:17 -04:00
| `--no-minify` | `false` | Build website without minimizing JS/CSS bundles. |
2019-05-17 07:01:34 -04:00
2020-03-29 00:10:50 -04:00
:::important
2020-04-14 14:38:55 -04:00
Please note that some functionality (for example, anchor links) will not work in development. The functionality will work as expected in production.
2020-03-29 00:10:50 -04:00
:::
2022-03-09 22:22:21 -05:00
:::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
```
:::
2021-06-16 05:04:40 -04:00
#### Enabling HTTPS {#enabling-https}
2020-10-26 12:28:12 -04:00
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 Docusaurus HTTPS env variables:
2021-12-27 06:34:04 -05:00
```bash
2020-10-26 12:28:12 -04:00
HTTPS=true SSL_CRT_FILE=localhost.pem SSL_KEY_FILE=localhost-key.pem yarn start
```
4. Open `https://localhost:3000/`
2021-03-19 06:00:41 -04:00
### `docusaurus build [siteDir]` {#docusaurus-build-sitedir}
2019-05-17 07:01:34 -04:00
Compiles your site for production.
2021-03-19 06:00:41 -04:00
#### Options {#options-1}
2019-05-17 07:01:34 -04:00
2020-04-14 11:26:55 -04:00
| Name | Default | Description |
2019-11-17 08:44:02 -05:00
| --- | --- | --- |
2020-05-17 23:37:53 -04:00
| `--bundle-analyzer` | `false` | Analyze your bundle with the [webpack bundle analyzer](https://github.com/webpack-contrib/webpack-bundle-analyzer). |
2020-03-19 11:52:26 -04:00
| `--out-dir` | `build` | The full path for the new output directory, relative to the current workspace. |
2022-06-15 01:04:33 -04:00
| `--config` | `undefined` | Path to Docusaurus config file, default to `[siteDir]/docusaurus.config.js` |
2020-03-29 11:32:26 -04:00
| `--no-minify` | `false` | Build website without minimizing JS/CSS bundles. |
2019-05-17 07:01:34 -04:00
2020-11-13 08:06:24 -05:00
:::info
2023-01-05 07:28:30 -05:00
For advanced minification of CSS bundle, we use the [advanced cssnano preset](https://github.com/cssnano/cssnano/tree/master/packages/cssnano-preset-advanced) (along with additional several PostCSS plugins) and [level 2 optimization of clean-css](https://github.com/jakubpawlowicz/clean-css#level-2-optimizations). If as a result of this advanced CSS minification you find broken CSS, build your website with the environment variable `USE_SIMPLE_CSS_MINIFIER=true` to minify CSS with the [default cssnano preset](https://github.com/cssnano/cssnano/tree/master/packages/cssnano-preset-default). **Please [fill out an issue](https://github.com/facebook/docusaurus/issues/new?labels=bug%2C+needs+triage&template=bug.md) if you experience CSS minification bugs.**
2020-11-13 08:06:24 -05:00
2022-06-15 12:41:03 -04:00
You can skip the HTML minification with the environment variable `SKIP_HTML_MINIFICATION=true`.
2020-11-13 08:06:24 -05:00
:::
2022-02-25 08:13:15 -05:00
### `docusaurus swizzle [themeName] [componentName] [siteDir]` {#docusaurus-swizzle}
2019-05-17 07:01:34 -04:00
2022-12-30 09:08:28 -05:00
[Swizzle](./swizzling.mdx) a theme component to customize it.
2019-05-17 07:01:34 -04:00
2021-02-22 14:38:05 -05:00
```bash npm2yarn
npm run swizzle [themeName] [componentName] [siteDir]
2020-04-27 22:53:45 -04:00
2020-05-17 23:37:53 -04:00
# Example (leaving out the siteDir to indicate this directory)
2022-02-25 08:13:15 -05:00
npm run swizzle @docusaurus/theme-classic Footer -- --eject
2019-05-17 07:01:34 -04:00
```
2022-12-30 09:08:28 -05:00
The swizzle CLI is interactive and will guide you through the whole [swizzle process](./swizzling.mdx).
2019-05-17 07:01:34 -04:00
2022-02-25 08:13:15 -05:00
#### Options {#options-swizzle}
2020-08-06 07:53:03 -04:00
2022-10-20 10:11:39 -04:00
| 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 |
2022-12-30 09:08:28 -05:00
| `--eject` | [Eject](./swizzling.mdx#ejecting) the theme component |
| `--wrap` | [Wrap](./swizzling.mdx#wrapping) the theme component |
2022-10-20 10:11:39 -04:00
| `--danger` | Allow immediate swizzling of unsafe components |
| `--typescript` | Swizzle the TypeScript variant component |
| `--config` | Path to docusaurus config file, default to `[siteDir]/docusaurus.config.js` |
2019-05-17 07:01:34 -04:00
2021-02-22 14:38:05 -05:00
:::caution
2022-02-25 08:13:15 -05:00
Unsafe components have a higher risk of breaking changes due to internal refactorings.
2021-02-22 14:38:05 -05:00
:::
2021-03-19 06:00:41 -04:00
### `docusaurus deploy [siteDir]` {#docusaurus-deploy-sitedir}
2019-05-17 07:01:34 -04:00
2020-11-05 12:22:18 -05:00
Deploys your site with [GitHub Pages](https://pages.github.com/). Check out the docs on [deployment](deployment.mdx#deploying-to-github-pages) for more details.
2020-03-19 11:52:26 -04:00
2021-03-19 06:00:41 -04:00
#### Options {#options-3}
2020-03-19 11:52:26 -04:00
2020-04-14 11:26:55 -04:00
| Name | Default | Description |
2020-03-19 11:52:26 -04:00
| --- | --- | --- |
| `--out-dir` | `build` | The full path for the new output directory, relative to the current workspace. |
2021-12-27 06:34:04 -05:00
| `--skip-build` | `false` | Deploy website without building it. This may be useful when using a custom deploy script. |
2022-06-15 01:04:33 -04:00
| `--config` | `undefined` | Path to Docusaurus config file, default to `[siteDir]/docusaurus.config.js` |
2020-07-20 13:00:37 -04:00
2021-03-19 06:00:41 -04:00
### `docusaurus serve [siteDir]` {#docusaurus-serve-sitedir}
2020-07-20 13:00:37 -04:00
docs(v2): fix simple typo, localy -> locally (#3480)
There is a small typo in website/docs/cli.md, website/docs/deployment.md, website/versioned_docs/version-2.0.0-alpha.60/cli.md, website/versioned_docs/version-2.0.0-alpha.60/deployment.md, website/versioned_docs/version-2.0.0-alpha.61/cli.md, website/versioned_docs/version-2.0.0-alpha.61/deployment.md, website/versioned_docs/version-2.0.0-alpha.62/cli.md, website/versioned_docs/version-2.0.0-alpha.62/deployment.md, website/versioned_docs/version-2.0.0-alpha.63/cli.md, website/versioned_docs/version-2.0.0-alpha.63/deployment.md, website/versioned_docs/version-2.0.0-alpha.64/cli.md, website/versioned_docs/version-2.0.0-alpha.64/deployment.md.
Should read `locally` rather than `localy`.
2020-09-23 15:50:06 -04:00
Serve your built website locally.
2020-07-20 13:00:37 -04:00
| 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 |
2022-06-15 01:04:33 -04:00
| `--config` | `undefined` | Path to Docusaurus config file, default to `[siteDir]/docusaurus.config.js` |
2020-07-20 13:00:37 -04:00
| `--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`. |
2022-05-27 04:45:53 -04:00
| `--no-open` | `false` locally, `true` in CI | Do not open a browser window to the server location. |
2020-09-28 10:33:35 -04:00
2021-03-19 06:00:41 -04:00
### `docusaurus clear [siteDir]` {#docusaurus-clear-sitedir}
2020-09-28 10:33:35 -04:00
2020-10-07 06:39:47 -04:00
Clear a Docusaurus site's generated assets, caches, build artifacts.
2020-09-28 10:33:35 -04:00
We recommend running this command before reporting bugs, after upgrading versions, or anytime you have issues with your Docusaurus site.
2021-01-19 11:26:31 -05:00
2021-03-19 06:00:41 -04:00
### `docusaurus write-translations [siteDir]` {#docusaurus-write-translations-sitedir}
2021-01-19 11:26:31 -05:00
Write the JSON translation files that you will have to translate.
By default, the files are written in `website/i18n/<defaultLocale>/...`.
| Name | Default | Description |
| --- | --- | --- |
| `--locale` | `<defaultLocale>` | Define which locale folder you want to write translations the JSON files in |
| `--override` | `false` | Override existing translation messages |
2022-06-15 01:04:33 -04:00
| `--config` | `undefined` | Path to Docusaurus config file, default to `[siteDir]/docusaurus.config.js` |
2021-12-27 06:34:04 -05:00
| `--messagePrefix` | `''` | Allows adding a prefix to each translation message, to help you highlight untranslated strings |
2021-03-05 13:36:14 -05:00
2021-10-21 06:33:52 -04:00
### `docusaurus write-heading-ids [siteDir] [files]` {#docusaurus-write-heading-ids-sitedir}
2021-03-05 13:36:14 -05:00
2022-06-15 01:04:33 -04:00
Add [explicit heading IDs](./guides/markdown-features/markdown-features-toc.mdx#explicit-ids) to the Markdown documents of your site.
2021-10-21 06:33:52 -04:00
| Name | Default | Description |
| --- | --- | --- |
| `files` | All MD files used by plugins | The files that you want heading IDs to be written to. |
| `--maintain-case` | `false` | Keep the headings' casing, otherwise make all lowercase. |
| `--overwrite` | `false` | Overwrite existing heading IDs. |