版本:Canary 🚧



npm run build

完成后,静态文件会被生成在 build 目录中。


Docusaurus 只负责构建站点,然后把静态文件输出到 build 文件夹。


You can deploy your site to static site hosting services such as Vercel, GitHub Pages, Netlify, Render, and Surge.

Docusaurus 网站是静态渲染的,而且一般不需要 JavaScript 也能运行!


docusaurus.config.js 中,下面这些参数是必填的,让 Docusaurus 能够优化路由,并从正确的位置加载文件:

url站点 URL。 如果网站部署在 https://my-org.com/my-project/url 就是 https://my-org.com/
baseUrl站点的 base URL,带有末尾斜杠。 如果网站部署在 https://my-org.com/my-project/ baseUrl 就是 /my-project/


在部署到生产环境前,事先进行本地测试尤为重要。 Docusaurus 提供了 docusaurus serve 命令来测试:

npm run serve

By default, this will load your site at http://localhost:3000/.


Docusaurus has a trailingSlash config to allow customizing URLs/links and emitted filename patterns.

你一般不需要修改默认值。 遗憾的是,每家静态托管商的行为都不一样,而把同一网站部署到不同服务商的结果可能大相径庭。 根据你的托管商的不同,你可能需要修改此配置。


要更好地了解你的托管商的行为,可以参见 slorber/trailing-slash-guide,并依此配置 trailingSlash 选项。


把可能敏感的信息放在环境变量中的做法很常见。 However, in a typical Docusaurus website, the docusaurus.config.js file is the only interface to the Node.js environment (see our architecture overview), while everything else (MDX pages, React components, etc.) are client side and do not have direct access to the process global variable. 在这种情况下,你可以考虑使用 customFields 将环境变量传递给客户端。

// 如果你用 dotenv (https://www.npmjs.com/package/dotenv)

module.exports = {
title: '...',
url: process.env.URL, // 你也可以通过环境变量控制网站细节
customFields: {
// 把你的自定义环境放在这里
teamEmail: process.env.EMAIL,
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';

export default function Home() {
const {
siteConfig: {customFields},
} = useDocusaurusContext();
return <div>通过 {customFields.teamEmail} 联系我们!</div>;



  • Self hosting with an HTTP server like Apache2 or Nginx.
  • Jamstack providers (e.g. Netlify and Vercel). 我们会以它们为参考,但同样的道理也可以适用于其他提供商。
  • GitHub Pages (by definition, it is also Jamstack, but we compare it separately).


How many resources (money, person-hours, etc.) am I willing to invest in this?

  • 🔴 Self-hosting requires experience in networking as well as Linux and web server administration. It's the most difficult option, and would require the most time to manage successfully. Expense-wise, cloud services are almost never free, and purchasing/deploying an onsite server can be even more costly.
  • 🟢 Jamstack 提供商可以帮助你建立一个运转良好的网站,几乎不需要时间,并且很容易配置功能,比如服务端重定向。 Many providers offer generous build-time quotas even for free plans that you would almost never exceed. However, free plans have limits, and you would need to pay once you hit those limits. 要了解详情,请查看你的提供商的定价页面。
  • 🟡 GitHub Pages 部署的工作流程设置起来可能很麻烦。 (不信的话,可以看看部署到 GitHub Pages 部分的长度!) 但是,这项服务(包括构建和部署)对所有公共仓库都永久免费,并且我们也有详细教程,帮助你正确运行它。
How much server-side customization do I need?
  • 🟢 自行托管时,你可以控制整个服务器的配置。 You can configure the virtual host to serve different content based on the request URL, you can do complicated server-side redirects, you can implement authentication, and so on. 如果你需要很多服务器端功能,请选择自行托管网站。
  • 🟡 Jamstack usually offers some server-side configuration (e.g. URL formatting (trailing slashes), server-side redirects, etc.).
  • 🔴 GitHub Pages doesn't expose server-side configuration besides enforcing HTTPS and setting CNAME records.
Do I need collaboration-friendly deployment workflows?
  • 🟡 Self-hosted services can leverage continuous deployment functionality like Netlify, but more heavy-lifting is involved. Usually, you would designate a specific person to manage the deployment, and the workflow wouldn't be very git-based as opposed to the other two options.
  • 🟢 Netlify 和 Vercel 对每个 Pull Request 都会生成部署预览,这对于在合并到生产环境之前的团队审核工作非常有用。 你也可以做团队管理,不同成员拥有不同的部署访问权限。
  • 🟡 GitHub 页面不能做部署预览,至少方法非常复杂。 每个仓库只能和一个站点部署相关联。 另一方面,你还是可以控制哪些人有站点部署的写权限。

不存在通用方案。 你需要权衡你的需求和资源,然后再做决定。


你可以用 docusaurus service 命令来自行托管 Docusaurus。 可以用 --port--host 来分别更改端口和绑定主机。

npm run serve -- --build --port 80 --host

相较于其他静态托管提供商 / CDN,这不是最佳解决方案。


在后面几节中,我们会介绍几个常用的托管提供商,以及如何做最有效的 Docusaurus 部署设置。 Docusaurus is not affiliated with any of these services, and this information is provided for convenience only. Some of the write-ups are provided by third-parties, and recent API changes may not be reflected on our side. If you see outdated content, PRs are welcome.

Because we can only provide this content on a best-effort basis only, we have stopped accepting PRs adding new hosting options. 不过你可以在其他网站上写一篇关于某个服务提供商的文章(比如你的博客,或者提供商官网),然后让我们添加一个这篇文章的链接。

部署到 Netlify

要把 Docusaurus 2 站点部署到 Netlify,请先确保正确配置下列选项:

module.exports = {
url: 'https://docusaurus-2.netlify.app', // 你的网站的 URL,没有 末尾斜杠
baseUrl: '/', // 你的站点相对于仓库的路径
// ...

然后,用 Netlify 创建你的网站


  • 构建指令:npm run build
  • 发布目录:build

如果你没有设置这些构建选项,你还是可以在创建站点之后前往 "Site settings" -> "Build & deploy" 完成配置。

用上述选项配置完毕后,你的网站就会在有代码合并到部署分支(默认为 main)时自动重新部署,


某些 Docusaurus 网站把 docs 文件夹放在 website 之外(尤其是从 Docusaurus v1 迁移而来的站点):

repo           # git 根目录
├── docs # MD 文件
└── website # Docusaurus 根目录

如果你选择用 website 文件夹作为 Netlify 的 base directory,那么更新 docs 时,Netlify 不会触发构建。你需要配置自定义 ignore 命令

ignore = "git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF . ../docs/"

默认情况下,Netlify 会为 Docusaurus URL 添加末尾斜杠。

It is recommended to disable the Netlify setting Post Processing > Asset Optimization > Pretty Urls to prevent lowercase URLs, unnecessary redirects, and 404 errors.

特别当心Disable asset optimization 的全局选项不能正常工作,实际上并不会禁用 Pretty URLs 设置。 请确保单独取消勾选了 "Pretty URLs"

如果你想保持开启 Pretty URLs Netlify 设置,就要适当配置 Docusaurus 的 trailingSlash 选项。

更多信息请参阅 slorber/trailing-slash-guide

部署到 Vercel

部署 Docusaurus 项目到 Vercel 会带来多项收益,包括性能、易用性,等等。

要通过 Vercel 的 Git 集成部署你的 Docusaurus 项目,先确保项目已经被推送到了某个 Git 仓库中。

Import Flow 把项目导入进 Vercel。 During the import, you will find all relevant options preconfigured for you; however, you can choose to change any of these options.

项目导入完成后,所有分支的后续推送都会生成部署预览。所有生产分支(通常是 "main" 或 "master")的变更都会触发生产部署

部署到 GitHub Pages

Docusaurus provides an easy way to publish to GitHub Pages, which comes free with every GitHub repository.


Usually, there are two repositories (at least two branches) involved in a publishing process: the branch containing the source files, and the branch containing the build output to be served with GitHub Pages. 在下面的教程中,我们会把这两个仓库(分支)分别叫作源仓库(分支)部署仓库(分支)

每个 GitHub 仓库都关联有一个 GitHub Pages 服务。 如果部署仓库叫作 my-org/my-projectmy-org 是组织名或用户名),那么网站会被部署在 https://my-org.github.io/my-project/ 处。 If the deployment repository is called my-org/my-org.github.io (the organization GitHub Pages repo), the site will appear at https://my-org.github.io/.


如果你需要为 GitHub Pages 自定义域名,可以在 static 目录中创建一个 CNAME 文件。 static 目录中的内容会在部署时被复制到 build 文件夹的根部。 使用自定义域名时,就可以把 baseUrl: '/projectName/' 改回 baseUrl: '/' 了,也可以把 url 设置成你的自定义域名。

你可以参阅 GitHub Pages 的关于 GitHub Pages 文档了解详情。

Github Pages 会从默认分支(一般是 master/main)或者 gh-pages 分支中提取部署文件(运行 docusaurus build 产生的文件)。文件可以放在根目录,也可以放在 /docs 目录中。 你可以在仓库的 Settings > Pages 处配置。 这个分支会被称作「部署分支」。

我们提供了 docusaurus deploy 命令,帮助你从源仓库部署到部署仓库,一步完成克隆、构建、提交。

docusaurus.config.js 设置

首先,修改你的 docusaurus.config.js,添加如下参数:

organizationName拥有部署仓库的 GitHub 用户或组织。
deploymentBranchThe name of the deployment branch. It defaults to 'gh-pages' for non-organization GitHub Pages repos (projectName not ending in .github.io). Otherwise, it needs to be explicit as a config field or environment variable.

These fields also have their environment variable counterparts which have a higher priority: ORGANIZATION_NAME, PROJECT_NAME, and DEPLOYMENT_BRANCH.


GitHub Pages 默认为 Docusaurus 网址链接添加末尾斜杠。 建议设置 trailingSlashtruefalse 都可以,只要不是 undefined)。


module.exports = {
// ...
url: 'https://endiliey.github.io', // 你的网站 URL
baseUrl: '/',
projectName: 'endiliey.github.io',
organizationName: 'endiliey',
trailingSlash: false,
// ...

默认情况下,GitHub Pages 会用 Jekyll 构建要被发布的文件。 因为 Jekyll 会忽略所有以 _ 开头的文件,所以我们推荐你在 static 文件夹中新建一个 .nojekyll 文件来禁用 Jekyll。


USE_SSH设置为 true 时,会用 SSH 而不是默认的 HTTPS 来连接到 GitHub 源仓库。 如果源仓库的地址是 SSH URL(比如 [email protected]:facebook/docusaurus.git),USE_SSH 会被推断为 true
GIT_USER用于推送部署文件的 GitHub 账户用户名,需要有部署仓库的推送权限。 对于你自己的仓库,这一般会是你自己的 GitHub 用户名。 不使用 SSH 时必填,使用 SSH 时则会被忽略。
GIT_PASSGitHub 用户(GIT_USER 所指定)的 personal access token,用于非交互式部署(如持续部署)
CURRENT_BRANCH源分支。 这个分支一般是 mainmaster,但它也可以是 gh-pages 之外的任何分支。 如果变量没有赋值,那么会使用 docusaurus deploy 被调用时的分支。
GIT_USER_NAMEThe git config user.name value to use when pushing to the deployment repo
GIT_USER_EMAILThe git config user.email value to use when pushing to the deployment repo

GitHub 企业安装版应该和 github.com 的工作方式一致。你只需要在环境变量中设置组织的 GitHub 企业主机即可。

GITHUB_HOST你的 GitHub 企业网站的域名。
GITHUB_PORT你的 GitHub 企业网站的端口。


最后,要把你的网站部署到 GitHub Pages 上,请运行:


从 2021 年 8 月开始,GitHub 要求每次命令行登录都使用个人访问令牌,而不是密码。 当 GitHub 提示你输入密码时,请输入个人访问令牌。 更多信息请见 GitHub 文档

或者,你也可以使用 SSH (USE_SSH=true) 登录。

触发 GitHub Actions 部署

GitHub Actions 允许你在仓库中完成软件开发流程的自动化、自定义执行。

下面的工作流示例会假设你的网站源码在仓库的 main 分支(也就是_源分支_为 main),而发布源设置为 gh-pages 分支(也就是_部署分支_为 gh-pages)。


  1. 当向 main 发起新的拉取请求时,有一个 action 确保网站构建成功,但不会真正部署。 这个 job 会被称为 test-deploy
  2. 当一个拉取请求被合并到 main 分支,或直接向 main 分支推送时,站点会被构建并部署到 gh-pages 分支。 在这之后,新的构建输出会被发布在 GitHub Pages 网站上。 这个 job 会被称为 deploy

下面是两种通过 GitHub Actions 部署文档的方法。 根据你的部署分支的位置 (gh-pages),选择相应的选项:

  • 源代码仓库和部署代码仓库是同一仓库。
  • 部署仓库是一个远程仓库,和源仓库不同。

While you can have both jobs defined in the same workflow file, the original deploy workflow will always be listed as skipped in the PR check suite status, which is not indicative of the actual status and provides no value to the review process. 所以,我们建议把它们作为单独的工作流来管理。

我们会使用一个流行的第三方部署 action:peaceiris/actions-gh-pages

GitHub action 文件



这些文件假设你使用的是 Yarn。 如果你用的是 npm,需要把 cache: yarnyarn install --frozen-lockfileyarn build 分别修改成 cache: npmnpm cinpm run build

如果你的 Docusaurus 项目不在你的仓库的根目录,你可能需要配置默认工作目录,并相应地调整路径。

name: Deploy to GitHub Pages

- main
# Review gh actions docs if you want to further define triggers, paths, etc
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on

contents: write

name: Deploy to GitHub Pages
runs-on: ubuntu-latest
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
node-version: 18
cache: yarn

- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build website
run: yarn build

# Popular action to deploy to GitHub Pages:
# Docs: https://github.com/peaceiris/actions-gh-pages#%EF%B8%8F-docusaurus
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
github_token: ${{ secrets.GITHUB_TOKEN }}
# Build output to publish to the `gh-pages` branch:
publish_dir: ./build
# The following lines assign commit authorship to the official
# GH-Actions bot for deploys to `gh-pages` branch:
# https://github.com/actions/checkout/issues/13#issuecomment-724415212
# The GH actions bot is used by default if you didn't specify the two fields.
# 你可以用自己的用户信息替换它们。
user_name: github-actions[bot]
user_email: 41898282+github-actions[bot]@users.noreply.github.com
name: Test deployment

- main
# Review gh actions docs if you want to further define triggers, paths, etc
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on

name: Test deployment
runs-on: ubuntu-latest
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
node-version: 18
cache: yarn

- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Test build website
run: yarn build

After pushing to main, if you don't see your site published at the desired location (for example, it says "There isn't a GitHub Pages site here", or it's showing your repo's README.md file), try the following:

  • Wait about three minutes and refresh. It may take a few minutes for GitHub pages to pick up the new files.
  • Check your repo's landing page for a little green tick next to the last commit's title, indicating the CI has passed. If you see a cross, it means the build or deployment failed, and you should check the log for more debugging information.
  • Click on the tick and make sure you see a "Deploy to GitHub Pages" workflow. Names like "pages build and deployment / deploy" are GitHub's default workflows, indicating your custom deployment workflow failed to be triggered at all. Make sure the YAML files are placed under the .github/workflows folder, and that the trigger condition is set correctly (e.g., if your default branch is "master" instead of "main", you need to change the on.push property).
  • Under your repo's Settings > Pages, make sure the "Source" (which is the source for the deployment files, not "source" as in our terminology) is set to "gh-pages" + "/ (root)", since we are using gh-pages as the deployment branch.

If you are using a custom domain:

触发 Travis CI 部署

Continuous integration (CI) services are typically used to perform routine tasks whenever new commits are checked in to source control. These tasks can be any combination of running unit tests and integration tests, automating builds, publishing packages to npm, and deploying changes to your website. All you need to do to automate the deployment of your website is to invoke the yarn deploy script whenever your website is updated. The following section covers how to do just that using Travis CI, a popular continuous integration service provider.

  1. https://github.com/settings/tokens 上生成一个新 personal access token。 新建令牌时,授予它 repo 权限,这样它就有所有需要的权限了。
  2. 用你的 GitHub 账户把 Travis CI 应用添加到你想要激活的仓库中。
  3. 打开你的 Travis CI 主界面。 URL 大概像 https://travisenci.com/USERNAME/REPO,并导航到你的仓库的 More options > Setting > Environment Variables 部分。
  4. 创建一个新环境变量,命名为 GH_TOKEN,值为你刚刚生成的令牌。再创建 GH_EMAILGH_NAME 两个变量,对应你的邮箱和 GitHub 用户名。
  5. 在仓库根目录创建一个 .travis.yml 文件,包含下面的内容:
language: node_js
- 18
- main
yarn: true
- git config --global user.name "${GH_NAME}"
- git config --global user.email "${GH_EMAIL}"
- echo "machine github.com login ${GH_NAME} password ${GH_TOKEN}" > ~/.netrc
- yarn install
- GIT_USER="${GH_NAME}" yarn deploy

Now, whenever a new commit lands in main, Travis CI will run your suite of tests and if everything passes, your website will be deployed via the yarn deploy script.

触发 Buddy 部署

Buddy is an easy-to-use CI/CD tool that allows you to automate the deployment of your portal to different environments, including GitHub Pages.

Follow these steps to create a pipeline that automatically deploys a new version of your website whenever you push changes to the selected branch of your project:

  1. https://github.com/settings/tokens 上生成一个新 personal access token。 新建令牌时,授予它 repo 权限,这样它就有所有需要的权限了。
  2. 登录 Buddy 帐户并创建一个新项目。
  3. 选择 GitHub 作为 git 托管提供商,并选择包含你的网站源码的仓库。
  4. 在左侧的导航面板中,切换到 Pipelines 页面。
  5. 创建一个新的管道。 输入一个名称,把触发模式设置为 On push,然后选择会触发管道执行的分支。
  6. 添加一个 Node.js action。
  7. 在 action 的终端中添加以下指令:
git config --global user.email "<YOUR_GH_EMAIL>"
git config --global user.name "<YOUR_GH_USERNAME>"
yarn deploy

After creating this simple pipeline, each new commit pushed to the branch you selected deploys your website to GitHub Pages using yarn deploy. Read this guide to learn more about setting up a CI/CD pipeline for Docusaurus.

使用 Azure Pipelines

  1. 如果你尚未注册,请在 Azure Pipelines 处注册。
  2. 创建一个组织。 在组织内创建一个项目,连接到你的 GitHub 仓库。
  3. https://github.com/settings/tokens 上生成一个新 personal access token,包括 repo 权限。
  4. 在项目页面(类似 https://dev.azure.com/ORG_NAME/REPO_NAME/_build),新建一个管道,包含如下文本。 点击编辑,创建一个新环境变量,命名为 GH_TOKEN,值为你刚刚生成的令牌。再创建 GH_EMAILGH_NAME 两个变量,对应你的邮箱和 GitHub 用户名。 确保把它们标记为私密。 或者,你也可以在仓库根目录添加一个 azure-pipelines.yml 文件。
- main

vmImage: ubuntu-latest

- checkout: self
persistCredentials: true

- task: NodeTool@0
versionSpec: '18'
displayName: Install Node.js

- script: |
git config --global user.name "${GH_NAME}"
git config --global user.email "${GH_EMAIL}"
git checkout -b main
echo "machine github.com login ${GH_NAME} password ${GH_TOKEN}" > ~/.netrc
yarn install
GIT_USER="${GH_NAME}" yarn deploy
displayName: Install and build

使用 Drone

  1. 创建一个新的 SSH 密钥,它会是你的项目的部署密钥
  2. 命名你的私钥和公钥,确保它们不会覆盖其他 SSH 密钥
  3. https://github.com/USERNAME/REPO/settings/keys 上,添加一个新部署密钥,把你刚刚生成的公钥粘贴进去。
  4. 打开你的 Drone.io 界面并登录。 URL 看起来像 https://cloud.drone.io/USERNAME/REPO
  5. 点击仓库,点击激活仓库,并添加一个名为 git_depu_private_key 的秘密,值为你刚刚生成的私钥。
  6. 在仓库根目录创建一个 .drone.yml 文件,包含下面的内容:
kind: pipeline
type: docker
- tag
- name: Website
image: node
- mkdir -p $HOME/.ssh
- ssh-keyscan -t rsa github.com >> $HOME/.ssh/known_hosts
- echo "$GITHUB_PRIVATE_KEY" > "$HOME/.ssh/id_rsa"
- chmod 0600 $HOME/.ssh/id_rsa
- cd website
- yarn install
- yarn deploy
USE_SSH: true
from_secret: git_deploy_private_key

Now, whenever you push a new tag to GitHub, this trigger will start the drone CI job to publish your website.

Deploying to Flightcontrol

Flightcontrol is a service that automatically builds and deploys your web apps to AWS Fargate directly from your Git repository. It gives you full access to inspect and make infrastructure changes without the limitations of a traditional PaaS.

Get started by following Flightcontrol's step-by-step Docusaurus guide.

Deploying to Koyeb

Koyeb is a developer-friendly serverless platform to deploy apps globally. The platform lets you seamlessly run Docker containers, web apps, and APIs with git-based deployment, native autoscaling, a global edge network, and built-in service mesh and discovery. Check out the Koyeb's Docusaurus deployment guide to get started.

Deploying to Render

Render offers free static site hosting with fully managed SSL, custom domains, a global CDN, and continuous auto-deploy from your Git repo. Get started in just a few minutes by following Render's guide to deploying Docusaurus.

Deploying to Qovery

Qovery is a fully-managed cloud platform that runs on your AWS, Digital Ocean, and Scaleway account where you can host static sites, backend APIs, databases, cron jobs, and all your other apps in one place.

  1. 新建一个 Qovery 账户。 如果你还没有账户,可以在 Qovery 界面创建一个。
  2. 新建一个项目。
    • 点击 Create project 并给你的项目命名。
    • 点击 Next
  3. 新建一个环境。
    • 点击 Create environment 并给它命名(比如 staging, production 等)。
  4. 添加一个应用。
    • 点击 Create an application,给它命名,并选择你的 Docusaurus 应用所在的 GitHub 或 GitLab 仓库。
    • 定义主分支名称和应用的根目录。
    • 点击 Create。 应用创建完毕后:
    • 前往应用的 Settings
    • 选择 Port
    • 添加你的 Docusaurus 应用使用的端口
  5. 部署
    • All you have to do now is to navigate to your application and click on Deploy.

Deploy the app

That's it. Watch the status and wait till the app is deployed. To open the application in your browser, click on Action and Open in your application overview.

Deploying to Hostman

Hostman allows you to host static websites for free. Hostman automates everything, you just need to connect your repository and follow these easy steps:

  1. Create a service.

    • To deploy a Docusaurus static website, click Create in the top-left corner of your Dashboard and choose Front-end app or static website.
  2. Select the project to deploy.

    • If you are logged in to Hostman with your GitHub, GitLab, or Bitbucket account, you will see the repository with your projects, including the private ones.

    • Choose the project you want to deploy. It must contain the directory with the project's files (e.g. website).

    • To access a different repository, click Connect another repository.

    • If you didn't use your Git account credentials to log in, you'll be able to access the necessary account now, and then select the project.

  3. Configure the build settings.

    • Next, the Website customization window will appear. Choose the Static website option from the list of frameworks.

    • The Directory with app points at the directory that will contain the project's files after the build. If you selected the repository with the contents of the website (or my_website) directory during Step 2, you can leave it empty.

    • The standard build command for Docusaurus is:

      npm run build
    • You can modify the build command if needed. You can enter multiple commands separated by &&.

  4. Deploy.

    • Click Deploy to start the build process.

    • Once it starts, you will enter the deployment log. If there are any issues with the code, you will get warning or error messages in the log specifying the cause of the problem. Usually, the log contains all the debugging data you'll need.

    • When the deployment is complete, you will receive an email notification and also see a log entry. All done! Your project is up and ready.

Deploying to Surge

Surge is a static web hosting platform that you can use to deploy your Docusaurus project from the command line in seconds. Deploying your project to Surge is easy and free (including custom domains and SSL certs).

Deploy your app in a matter of seconds using surge with the following steps:

  1. First, install Surge using npm by running the following command:
    npm install -g surge
  2. To build the static files of your site for production in the root directory of your project, run:
    npm run build
  3. Then, run this command inside the root directory of your project:
    surge build/

First-time users of Surge would be prompted to create an account from the command line (which happens only once).

Confirm that the site you want to publish is in the build directory. A randomly generated subdomain *.surge.sh subdomain is always given (which can be edited).


If you have a domain name you can deploy your site using the command:

surge build/ your-domain.com

Your site is now deployed for free at subdomain.surge.sh or your-domain.com depending on the method you chose.

配置 CNAME 文件

Store your domain in a CNAME file for future deployments with the following command:

echo subdomain.surge.sh > CNAME

You can deploy any other changes in the future with the command surge.

Deploying to QuantCDN

  1. Install Quant CLI
  2. Create a QuantCDN account by signing up
  3. Initialize your project with quant init and fill in your credentials:
    quant init
  4. Deploy your site.
    quant deploy

See docs and blog for more examples and use cases for deploying to QuantCDN.

Deploying to Layer0

Layer0 is an all-in-one platform to develop, deploy, preview, experiment on, monitor, and run your headless frontend. It is focused on large, dynamic websites and best-in-class performance through EdgeJS (a JavaScript-based Content Delivery Network), predictive prefetching, and performance monitoring. Layer0 offers a free tier. Get started in just a few minutes by following Layer0's guide to deploying Docusaurus.

Deploying to Cloudflare Pages

Cloudflare Pages is a Jamstack platform for frontend developers to collaborate and deploy websites. Get started within a few minutes by following this article.

Deploying to Azure Static Web Apps

Azure Static Web Apps is a service that automatically builds and deploys full-stack web apps to Azure directly from the code repository, simplifying the developer experience for CI/CD. Static Web Apps separates the web application's static assets from its dynamic (API) endpoints. Static assets are served from globally-distributed content servers, making it faster for clients to retrieve files using servers nearby. Dynamic APIs are scaled with serverless architectures using an event-driven functions-based approach that is more cost-effective and scales on demand. Get started in a few minutes by following this step-by-step guide.

Deploying to Kinsta Application Hosting

Kinsta Application Hosting is a service that lets you build and deploy your web apps directly from your Git repository. Get started in just a minutes by following our Docusaurus on Kinsta article.