Skip to main content
Version: 2.0.0-alpha.70

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:

package.json
{
// ...
"scripts": {
"start": "docusaurus start",
"build": "docusaurus build",
"swizzle": "docusaurus swizzle",
"deploy": "docusaurus deploy",
"clear": "docusaurus clear"
}
}

Index#

Docusaurus CLI commands#

Below is a list of Docusaurus CLI commands and their usages:

docusaurus start#

Builds and serves a preview of your site locally with Webpack Dev Server.

Options#

NameDefaultDescription
--port3000Specifies the port of the dev server.
--hostlocalhostSpecify a host to use. For example, if you want your server to be accessible externally, you can use --host 0.0.0.0.
--hot-onlyfalseEnables Hot Module Replacement without page refresh as fallback in case of build failures. More information here.
--no-openfalseDo not open automatically the page in the browser.
--poll [optionalIntervalMs]falseUse polling of files rather than watching for live reload as a fallback in environments where watching doesn't work. More information here.
important

Please note that some functionality (for example, anchor links) will not work in development. The functionality will work as expected in production.

Enabling HTTPS`#

There are multiple ways to obtain a certificate. We will use 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:

HTTPS=true SSL_CRT_FILE=localhost.pem SSL_KEY_FILE=localhost-key.pem yarn start
  1. Open https://localhost:3000/

docusaurus build#

Compiles your site for production.

Options#

NameDefaultDescription
--bundle-analyzerfalseAnalyze your bundle with the webpack bundle analyzer.
--out-dirbuildThe full path for the new output directory, relative to the current workspace.
--no-minifyfalseBuild website without minimizing JS/CSS bundles.
info

For advanced minification of CSS bundle, we use the advanced cssnano preset (along with additional several PostCSS plugins) and level 2 optimization of clean-css. 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. Please fill out an issue if you experience CSS minification bugs.

docusaurus swizzle#

caution

We highly discourage swizzling of components until we've reached a Beta stage. The components APIs have been changing rapidly and are likely to keep changing until we reach Beta. Stick with the default appearance for now if possible to save yourself some potential pain in future.

Change any Docusaurus theme components to your liking with docusaurus swizzle.

docusaurus swizzle [themeName] [componentName] [siteDir]
# Example (leaving out the siteDir to indicate this directory)
docusaurus swizzle @docusaurus/theme-classic DocSidebar

Running the command will copy the relevant theme files to your site folder. You may then make any changes to it and Docusaurus will use it instead of the one provided from the theme.

docusaurus swizzle without themeName lists all the themes available for swizzling similarly docusaurus swizzle <themeName> without componentName lists all the components available for swizzling.

Options#

NameDescription
themeNameThe name of the theme you are using.
swizzleComponentThe name of the component to swizzle.
--dangerAllow swizzling of unstable components
--typescriptSwizzle TypeScript components

To unswizzle a component, simply delete the files of the swizzled component.

docusaurus deploy#

Deploys your site with GitHub Pages. Check out the docs on deployment for more details.

Options#

NameDefaultDescription
--out-dirbuildThe full path for the new output directory, relative to the current workspace.
--skip-buildfalseDeploy website without building it. This may be useful when using custom deploy script.

docusaurus serve#

Serve your built website locally.

NameDefaultDescription
--port3000Use specified port
--dirbuildThe full path for the output directory, relative to the current workspace
--buildfalseBuild website before serving
--hostlocalhostSpecify a host to use. For example, if you want your server to be accessible externally, you can use --host 0.0.0.0.

docusaurus clear#

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.

Last updated on by Sébastien Lorber