CLI
Docusaurusは、ウェブサイトの生成、配信、デプロイを支援するスクリプト一式を提供します。
ウェブサイトが初期設定されると、ウェブサイトのソースにDocusaurusスクリプトが含まれ、パッケージマネージャで起動できるようになります。
{
// ...
"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 | 説明 |
|---|---|---|
--port | 3000 | 開発サーバのポート番号を指定します。 |
--host | localhost | 使用するホスト名を指定します。 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 | ビルドに失敗した場合のフォールバックとして、ページ更新なしでのホットモジュールリプレースメントを有効にします。 More information here. |
--no-open | false | ブラウザでページを自動的に開かないようにします。 |
--config | undefined | Path to Docusaurus config file, default to [siteDir]/docusaurus.config.js |
--poll [optionalIntervalMs] | false | 監視が機能しない環境では、ライブ・リロードの監視ではなく、ファイルのポーリングをフォールバックとして使用します。 More information here. |
--no-minify | false | JS/CSSバンドルを最小化せずにウェブサイトをビルドします。 |
一部の機能(アンカーリンクなど)は開発段階では動作しませんのでご注意ください。 本機能は本番環境では期待通りに動作します。
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
- Yarn
- pnpm
- Bun
npm run start -- --host 0.0.0.0
yarn run start --host 0.0.0.0
pnpm run start --host 0.0.0.0
bun run start --host 0.0.0.0
HTTPSの有効化
証明書を取得する方法は複数あります。 We will use mkcert as an example.
-
Run
mkcert localhostto generatelocalhost.pem+localhost-key.pem -
Run
mkcert -installto install the cert in your trust store, and restart your browser -
次のように、Docusaurus HTTPS環境変数を指定してアプリを起動:
HTTPS=true SSL_CRT_FILE=localhost.pem SSL_KEY_FILE=localhost-key.pem yarn start
- Open
https://localhost:3000/
docusaurus build [siteDir]
サイトを本番用にコンパイルします。
Options
| 名前 | Default | 説明 |
|---|---|---|
--dev | Builds the website in dev mode, including full React error messages. | |
--bundle-analyzer | false | Analyze your bundle with the webpack bundle analyzer. |
--out-dir | build | 現在のワークスペースからの相対パスで、新しい出力ディレクトリのフルパスです。 |
--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 | JS/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
- Yarn
- pnpm
- Bun
npm run swizzle [themeName] [componentName] [siteDir]
# 例(現在のディレクトリであることを示すためsiteDirは省略)
npm run swizzle @docusaurus/theme-classic Footer -- --eject
yarn swizzle [themeName] [componentName] [siteDir]
# 例(現在のディレクトリであることを示すためsiteDirは省略)
yarn swizzle @docusaurus/theme-classic Footer --eject
pnpm run swizzle [themeName] [componentName] [siteDir]
# 例(現在のディレクトリであることを示すためsiteDirは省略)
pnpm run swizzle @docusaurus/theme-classic Footer --eject
bun run swizzle [themeName] [componentName] [siteDir]
# 例(現在のディレクトリであることを示すためsiteDirは省略)
bun 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 | スウィズリング可能なコンポーネントを一覧表示 |
--eject | Eject the theme component |
--wrap | Wrap the theme component |
--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 |
安全でないコンポーネントは、内部のリファクタリングによって破壊的変更の影響に晒される危険性が高いです。
docusaurus deploy [siteDir]
Deploys your site with GitHub Pages. Check out the docs on deployment for more details.
Options
| 名前 | Default | 説明 |
|---|---|---|
--locale | Deploy the site in the specified locale(s). If not specified, all known locales are deployed. | |
--out-dir | build | 現在のワークスペースからの相対パスで、新しい出力ディレクトリのフルパスです。 |
--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]
Serve your built website locally.
| 名前 | Default | 説明 |
|---|---|---|
--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 | 使用するホスト名を指定します。 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. |
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 |
--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]
Add explicit heading IDs to the Markdown documents of your site.
| 名前 | Default | 説明 |
|---|---|---|
files | All MD files used by plugins | The files that you want heading IDs to be written to. |
--syntax | classic | Heading ID syntax to use: classic ({#id}) or mdx-comment ({/* #id */}). |
--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. |