CLI Commands
Docusaurus 提供了一组脚本来帮助您生成、服务和配置您的网站。 使用 Yarn 或 npm 时, 可以使用 run
命令调用这些脚本。 一些常见的命令如下:
-
yarn run star
: 从本地服务器生成并且维护这个网站 -
yarn run examples
: 创建示例配置文件
从命令行运行
这些脚本可以使用 Yarn 或 npm 来运行。 如果您已经完成了我们的入门指南, 您可能已经熟悉了 start
命令。 这是这样的命令,:它告诉 Docusaurus 运行 Docusaurus-start
脚本, 它生成站点并启动服务器, 通常是这样调用的:
yarn run start
也可以使用 npm 调用相同的脚本:
npm run start
若要运行特定的脚本, 只需用与脚本关联的命令替换上面示例中的 start
命令。
使用参数
Some commands support optional arguments. For example, to start a server on port 8080, you can specify the --port
argument when running start
:
yarn run start -- port 8080
如果使用 npm 运行 Docusaurus, 则仍然可以通过在 npm run <command>
和命令参数之间插入 --
来使用命令行参数:
npm run start -- --port 8080
配置
这些脚本是在 website/package.json
文件的 "scripts"
项下设置的, 作为安装过程的一部分。 如果需要帮助再次设置它们, 请参阅 安装指南 。
Docusaurus 提供了一些默认的映像, 允许您按照节点约定运行命令。 您可以键入 yarn run start
或 npm start
来实现相同的目的, 而不是每次都键入 docusaurus-start
。
命令
docusaurus-build
docusaurus-examples
docusaurus-publish
docusaurus-rename-version
docusaurus-start
docusaurus-版本
docusaurus-书写-翻译
参考
docusaurus-build
别名︰ build
。
可选项 | 默认 | 说明 |
---|---|---|
--skip-image-compression | false | 忽略图片资源压缩。 通常都不会跳过图片资源压缩,除非你的图片资源已经优化过。 |
生成静态站点,必要时会应用翻译。 适用于部署前构建站点。
另请参阅 docusaurus-start
。
docusaurus-examples
别名:examples
参数 | 默认 | 说明 |
---|---|---|
<feature> | - | 指定附加功能 translations 或 versions ,以生成附加功能的额外文件。 |
示例
docusaurus-examples <feature>
如果没有指定附加功能,则会在你的项目中设置一个最小化配置的示例站点。 Site Preparation guide 中会深入介绍此命令。
docusaurus-publish
别名: publish-gh-pages
Builds,然后在 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:
以下环境变量通常由用户在 CircleCI 的 config.yml
文件中手动设置。
GIT_USER
:与部署相关的 GIT 用户。USE_SSH
: Whether to use SSH instead of HTTPS for your connection to the GitHub repo.
示例
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
:与触发 CI 运行的 commit 相关联的 git 分支。CI_PULL_REQUEST
: 如果当前 CI 运行是通过请求中的提交触发的, 则认定为真。
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.
参数 | 默认 | 说明 |
---|---|---|
<currentVersion> | - | Version to be renamed. |
<newVersion> | - | Version to be renamed to. |
示例
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.
可选项 | 默认 | 说明 |
---|---|---|
--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-版本 <版本>
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-书写-翻译
Alias: write-translations
Writes the English for any strings that need to be translated into an 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.