Comandos de la CLI
Docusaurus proporciona un conjunto de scripts para ayudarlo a generar, abastecer e implementar su sitio web. Estos scripts se pueden invocar con el comando run
cuando se utiliza Yarn o npm. Algunos comandos comunes son:
-
yarn run start
: compila y abastece el sitio web desde un servidor local yarn run examples
: crear un ejemplo de archivos de configuración
Ejecución desde la línea de comandos
Los scripts se pueden ejecutar usando Yarn o npm. Si ya ha consultado nuestra guía de introducción, es posible que ya esté familiarizado con el comando start
. Es el comando que le dice a Docusaurus que ejecute el script docusaurus-start
que genera el sitio y arranca un servidor, y generalmente se invoca así:
yarn run start
El mismo script puede invocarse usando npm:
npm run start
Para ejecutar un script en particular, simplemente reemplace el comando start
en los ejemplos anteriores con el comando asociado con su script.
Usando argumentos
Algunos comandos soportan argumentos opcionales. Por ejemplo, para arrancar un servidor en el puerto 8080, puedes especificar el parámetro --port
cuando ejecutas start
:
yarn run start --port 8080
Si ejecuta Docusaurus utilizando npm, puede seguir utilizando los argumentos de la línea de comando insertando un --
entre npm run <command>
y los argumentos del comando:
npm run start -- --port 8080
Configuración
Estos scripts se configuran con la clave "scripts"
en su archivo website/package.json
como parte del proceso de instalación. Si necesita ayuda para configurarlas nuevamente, consulte la Guía de instalación .
Docusaurus proporciona algunas asignaciones predeterminadas que le permiten ejecutar comandos siguiendo las convenciones de Nodo. En lugar de escribir docusaurus-start
siempre, puede escribir yarn run start
o npm start
para lograr lo mismo.
Comandos
docusaurus-build
docusaurus-examples
docusaurus-publish
docusaurus-rename-version
docusaurus-start
docusaurus-version <version>
docusaurus-write-translations
Referencia
docusaurus-build
Alias: build
.
Options | Por defecto | Descripción |
---|---|---|
--skip-image-compression | false | Skip compression of image assets. Normalmente no querrás saltarte esto a menos que tus imagenes ya hayan sido optimizadas. |
--skip-next-release | false | Skip the next release documents when versioning is enabled. This will not build HTML files for documents in /docs directory. |
Generates the static website, applying translations if necessary. Useful for building the website prior to deployment.
Ver también docusaurus-start
.
docusaurus-examples
Alias: examples
Arguments | Por defecto | Descripción |
---|---|---|
<feature> | - | Specify a feature translations or versions to generate the extra example files for that feature. |
Ejemplo
docusaurus-examples <feature>
When no feature is specified, sets up a minimally configured example website in your project. This command is covered in depth in the Site Preparation guide.
docusaurus-publish
Alias: publish-gh-pages
Builds, then deploys the static website to GitHub Pages. This command is meant to be run during the deployment step in CircleCI, and therefore expects a few environment variables to be defined:
The following environment variables are generally set manually by the user in the CircleCI config.yml
file.
GIT_USER
: El usuario de git que se asociará con la implementación del commit.USE_SSH
: Whether to use SSH instead of HTTPS for your connection to the GitHub repo.
Ejemplo
GIT_USER=docusaurus-bot USE_SSH=true yarn run publish-gh-pages
The following environment variables are set by CircleCI during the build process.
CIRCLE_BRANCH
: El branch del git asociada con el commit que desencadenó la ejecución del CI.CI_PULL_REQUEST
: Se espera que sea cierto si la ejecución de CI actual fue desencadenada por un commit en una solicitud de extracción.
The following should be set by you in siteConfig.js
as organizationName
and projectName
, respectively. If they are not set in your site configuration, they fall back to the CircleCI environment.
CIRCLE_PROJECT_USERNAME
: The GitHub username or organization name that hosts the Git repo, e.g. "facebook".CIRCLE_PROJECT_REPONAME
: The name of the Git repo, e.g. "Docusaurus".
You can learn more about configuring automatic deployments with CircleCI in the Publishing guide.
docusaurus-rename-version
Alias: rename-version
Renames an existing version of the docs to a new version name.
Arguments | Por defecto | Descripción |
---|---|---|
<currentVersion> | - | Version to be renamed. |
<newVersion> | - | Version to be renamed to. |
Ejemplo
docusaurus-rename-version <currentVersion> <newVersion>
See the Versioning guide to learn more.
docusaurus-start
Alias: start
.
This command will build the static website, apply translations if necessary, and then start a local server.
Options | Por defecto | Descripción |
---|---|---|
-port <number> | 3000 | The website will be served from port 3000 by default, but if the port is taken up, Docusaurus will attempt to find an available one. |
--watch | - | Whether to watch the files and live reload the page when files are changed. Defaults to true. Disable this by using --no-watch . |
You can specify the browser application to be opened by setting the BROWSER
environment variable before the command, e.g.:
$ BROWSER=firefox yarn start
docusaurus-version <version>
Alias: version
Generates a new version of the docs. This will result in a new copy of your site being generated and stored in its own versioned directory. Useful for capturing snapshots of API docs that map to specific versions of your software. Accepts any string as a version number.
See the Versioning guide to learn more.
docusaurus-write-translations
Alias: write-translations
Writes the English for any strings that need to be translated into a website/i18n/en.json
file. The script will go through every file in website/pages/en
and through the siteConfig.js
file and other config files to fetch English strings that will then be translated on Crowdin. See the Translation guide to learn more.