Ir para o conteúdo principal
Version: 3.1.1

CLI

Docusaurus fornece um conjunto de scripts para ajudá-lo a gerar, servir e implantar seu site.

Assim que seu site for inicializado, a fonte do site conterá os scripts Docusaurus que você pode invocar com seu gerenciador de pacotes:

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

Abaixo está uma lista dos comandos do Docusaurus CLI e seus usos:

docusaurus start [siteDir]

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

Options

NomePadrãoDescrição
--devBuilds in dev mode, including full React error messages.
--port3000Especifica a porta do servidor de desenvolvimento.
--hostlocalhostEspecifique um host a ser usado. 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 a fallback in case of build failures. More information here.
--no-openfalseDo not open the page automatically in the browser.
--configundefinedPath to Docusaurus config file, default to [siteDir]/docusaurus.config.js
--poll [optionalIntervalMs]falseUse a pesquisa de arquivos em vez de observar a recarga ao vivo como uma alternativa em ambientes onde a vigilância não funciona. More information here.
--no-minifyfalseCrie um site sem minimizar os pacotes JS/CSS.
info

Por favor note que algumas funcionalidades (por exemplo, links de ancoragem) não funcionarão em desenvolvimento. A funcionalidade irá se comportar conforme o esperado em produção.

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

Enabling HTTPS

Existem várias maneiras de obter um certificado. 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. Inicie o aplicativo com variáveis de ambiente 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]

Compila seu local para produção.

Options

NomePadrãoDescrição
--bundle-analyzerfalseAnalyze your bundle with the webpack bundle analyzer.
--out-dirbuildO caminho completo para o novo diretório de saída, relativo ao espaço de trabalho atual.
--configundefinedPath to Docusaurus config file, default to [siteDir]/docusaurus.config.js
--no-minifyfalseCrie um site sem minimizar os pacotes JS/CSS.
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.

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]

# 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.

Options

NomeDescrição
themeNameThe name of the theme to swizzle from.
componentNameThe name of the theme component to swizzle.
--listDisplay components available for swizzling
--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
warning

Unsafe components have a higher risk of breaking changes due to internal refactorings.

docusaurus deploy [siteDir]

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

Options

NomePadrãoDescrição
--out-dirbuildO caminho completo para o novo diretório de saída, relativo ao espaço de trabalho atual.
--skip-buildfalseImplante o site sem construí-lo. This may be useful when using a custom deploy script.
--configundefinedPath to Docusaurus config file, default to [siteDir]/docusaurus.config.js

docusaurus serve [siteDir]

Disponibilize o site construído localmente.

NomePadrãoDescrição
--port3000Usar porta especificada
--dirbuildO caminho completo para o diretório de saída, relativo ao espaço de trabalho atual
--buildfalseCrie um site antes de servir
--configundefinedPath to Docusaurus config file, default to [siteDir]/docusaurus.config.js
--hostlocalhostEspecifique um host a ser usado. 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]

Limpe os assets gerados pelo site do Docusaurus. Caches e artefatos de construção.

Recomendamos executar esse comando antes de relatar bugs, depois de atualizar versões ou a qualquer momento que você tenha problemas com o seu site Docusaurus.

docusaurus write-translations [siteDir]

Escreva os arquivos de tradução JSON que você terá que traduzir.

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

NomePadrãoDescrição
--locale<defaultLocale>Defina em qual pasta de localização você deseja escrever as traduções dos arquivos JSON
--overridefalseSubstituir as mensagens de tradução existentes
--configundefinedPath to Docusaurus config file, default to [siteDir]/docusaurus.config.js
--messagePrefix''Permite adicionar um prefixo para cada mensagem de tradução, para ajudar a destacar strings não traduzidas

docusaurus write-heading-ids [siteDir] [files]

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

NomePadrãoDescrição
filesAll MD files used by pluginsThe files that you want heading IDs to be written to.
--maintain-casefalseKeep the headings' casing, otherwise make all lowercase.
--overwritefalseOverwrite existing heading IDs.