Skip to main content

CLI

Docusaurusは、ウェブサイトの生成、配信、デプロイを支援するスクリプト一式を提供します。

ウェブサイトが初期設定されると、ウェブサイトのソースにDocusaurusスクリプトが含まれ、パッケージマネージャで起動できるようになります。

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コマンド

以下は、DocusaurusのCLIコマンドとその使い方の一覧です。

docusaurus start [siteDir]

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

Options

名前Default説明
--port3000開発サーバのポート番号を指定します。
--hostlocalhost使用するホスト名を指定します。 For example, if you want your server to be accessible externally, you can use --host 0.0.0.0.
--localeSpecify site locale to be used.
--hot-onlyfalseビルドに失敗した場合のフォールバックとして、ページ更新なしでのホットモジュールリプレースメントを有効にします。 More information here.
--no-openfalseブラウザでページを自動的に開かないようにします。
--configundefinedPath to Docusaurus config file, default to [siteDir]/docusaurus.config.js
--poll [optionalIntervalMs]false監視が機能しない環境では、ライブ・リロードの監視ではなく、ファイルのポーリングをフォールバックとして使用します。 More information here.
--no-minifyfalseJS/CSSバンドルを最小化せずにウェブサイトをビルドします。
情報

一部の機能(アンカーリンクなど)は開発段階では動作しませんのでご注意ください。 本機能は本番環境では期待通りに動作します。

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.

npm run start -- --host 0.0.0.0

HTTPSの有効化

証明書を取得する方法は複数あります。 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. 次のように、Docusaurus HTTPS環境変数を指定してアプリを起動:

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

docusaurus build [siteDir]

サイトを本番用にコンパイルします。

Options

名前Default説明
--devBuilds the website in dev mode, including full React error messages.
--bundle-analyzerfalseAnalyze your bundle with the webpack bundle analyzer.
--out-dirbuild現在のワークスペースからの相対パスで、新しい出力ディレクトリのフルパスです。
--configundefinedPath to Docusaurus config file, default to [siteDir]/docusaurus.config.js
--localeBuild the site in the specified locale(s). If not specified, all known locales are built.
--no-minifyfalseJS/CSSバンドルを最小化せずにウェブサイトをビルドします。
情報

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.

You can skip the HTML minification with the environment variable SKIP_HTML_MINIFICATION=true.

docusaurus swizzle [themeName] [componentName] [siteDir]

Swizzle a theme component to customize it.

npm run swizzle [themeName] [componentName] [siteDir]

# 例(現在のディレクトリであることを示すためsiteDirは省略)
npm run swizzle @docusaurus/theme-classic Footer -- --eject

The swizzle CLI is interactive and will guide you through the whole swizzle process.

Options

名前説明
themeNameスウィズリング元のテーマ名
componentNameスウィズリング対象のテーマコンポーネント名
--listスウィズリング可能なコンポーネントを一覧表示
--ejectEject the theme component
--wrapWrap the theme component
--dangerAllow immediate swizzling of unsafe components
--typescriptSwizzle the TypeScript variant component
--configPath to docusaurus config file, default to [siteDir]/docusaurus.config.js
警告

安全でないコンポーネントは、内部のリファクタリングによって破壊的変更の影響に晒される危険性が高いです。

docusaurus deploy [siteDir]

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

Options

名前Default説明
--localeDeploy the site in the specified locale(s). If not specified, all known locales are deployed.
--out-dirbuild現在のワークスペースからの相対パスで、新しい出力ディレクトリのフルパスです。
--skip-buildfalseDeploy website without building it. This may be useful when using a custom deploy script.
--target-dir.Path to the target directory to deploy to.
--configundefinedPath to Docusaurus config file, default to [siteDir]/docusaurus.config.js

docusaurus serve [siteDir]

Serve your built website locally.

名前Default説明
--port3000Use specified port
--dirbuildThe full path for the output directory, relative to the current workspace
--buildfalseBuild website before serving
--configundefinedPath to Docusaurus config file, default to [siteDir]/docusaurus.config.js
--hostlocalhost使用するホスト名を指定します。 For example, if you want your server to be accessible externally, you can use --host 0.0.0.0.
--no-openfalse locally, true in CIDo not open a browser window to the server location.

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]

Write the JSON translation files that you will have to translate.

By default, the files are written in website/i18n/<defaultLocale>/....

名前Default説明
--locale<defaultLocale>Define which locale folder you want to write translations the JSON files in
--overridefalseOverride existing translation messages
--configundefinedPath 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]

Add explicit heading IDs to the Markdown documents of your site.

名前Default説明
filesAll MD files used by pluginsThe files that you want heading IDs to be written to.
--syntaxclassicHeading ID syntax to use: classic ({#id}) or mdx-comment ({/* #id */}).
--migratefalseMigrate existing heading IDs to the target --syntax, if they are using a different syntax.
--overwritefalseOverwrite existing heading IDs, re-generate them from the heading text.
--maintain-casefalseKeep the headings' casing, otherwise make all lowercase.