Installation
Docusaurus的初始设计就是要易于安装并让你的网站可以迅速运行。
安装 Docusaurus
我们创建了一个简单的脚本, 它将获得为您设置的所有基础结构:
确保您安装了最新版本的 Node。 我们同样建议您也安装 Yarn。
您必须有 Node > = 8. x 与 Yarn > = 1.5。
Create a project, if none exists, and change your directory to this project's root.
文档会被创建在此目录下。 根目录可能会包含其他文件。 Docusaurus的安装脚本会创建两个新目录:
docs
和website
。通常,Docusaurus 站点的位置会是现有或新创建的 GitHub 项目。但这不是 Docusaurus 的强制要求。
运行 Docusaurus 的安装脚本:
npx docusaurus-init
。如果您没有安装 Node 8.2 + ,或是您希望在全局范围内安装 Docusaurus,请运行
yarn global add docusaurus-init
或npm install --global docusaurus-init
。 安装完成后,运行docusaurus-init
。
验证安装
Along with previously existing files and directories, your root directory will now contain a structure similar to:
root-directory
├── Dockerfile
├── README.md
├── docker-compose.yml
├── docs
│ ├── doc1.md
│ ├── doc2.md
│ ├── doc3.md
│ ├── exampledoc4.md
│ └── exampledoc5.md
└── website
├── blog
│ ├── 2016-03-11-blog-post.md
│ ├── 2017-04-10-blog-post-two.md
│ ├── 2017-09-25-testing-rss.md
│ ├── 2017-09-26-adding-rss.md
│ └── 2017-10-24-new-version-1.0.0.md
├── core
│ └── Footer.js
├── package.json
├── pages
├── sidebars.json
├── siteConfig.js
└── static
运行示例网站
根据 Installation 部分所述运行 Docusaurus 的初始化脚本 docusaurus-init
后,你将会有一个可运行的示例网站。 要运行这个示例:
cd website
在
website
目录下,启动Docusaurus服务器:yarn start
或npm start
。如果没有自动打开已启动的示例网站,请从 http://localhost:3000 访问示例站点。 如果 3000 端口已被占用,将使用另一个端口。 查看控制台消息以确认使用了哪个端口。
You should see the example site loaded in your web browser. There's also a LiveReload server running and any changes made to the docs and files in the
website
directory will cause the page to refresh. Docusaurus将会自动选取一个随机生成的主要和次要主题颜色。
使用代理启动服务
If you are behind a corporate proxy, you need to disable it for the development server requests. It can be done using the NO_PROXY
environment variable.
SET NO_PROXY=localhost
yarn start (or npm run start)
Updating Your Docusaurus Version
在 Docusaurus 安装之后,你可以在 website
目录下查看最新版本,或是输入 yarn outdated docusaurus
或 npm outdated docusaurus
查看。
You will see something like this:
$ yarn outdated
Using globally installed version of Yarn
yarn outdated v1.5.1
warning package.json: No license field
warning No license field
info Color legend :
"<red>" : Major Update backward-incompatible updates
"<yellow>" : Minor Update backward-compatible features
"<green>" : Patch Update backward-compatible bug fixes
Package Current Wanted Latest Package Type URL
docusaurus 1.0.9 1.2.0 1.2.0 devDependencies https://github.com/facebook/docusaurus#readme
✨ Done in 0.41s.
如果
outdated
命令没有任何版本过期的通知,那你就处于最新版本。
You can update to the latest version of Docusaurus by:
yarn upgrade docusaurus --latest
或
npm update docusaurus
如果你在升级后发现任何错误,请尝试清除你的 Babel 缓存。通常在 temporary directory,或是在
BABEL_DISABLE_CACHE=1
的配置下运行 Docusaurus 服务(如:yarn start
)。