跳到主要内容
版本:Canary 🚧

自动迁移

迁移 CLI 工具会自动把你的 v1 站点迁移到 v2 版本。

信息

因为我们无法完全自动化迁移过程,所以你仍然需要在使用自动迁移工具之后,手动完成部分操作。

迁移 CLI 会迁移如下内容:

  • Site configurations (from siteConfig.js to docusaurus.config.js)
  • package.json
  • sidebars.json
  • /docs
  • /blog
  • /static
  • versioned_sidebar.json and /versioned_docs if your site uses versioning

迁移 CLI 的使用分为如下几步:

  1. Before using the migration CLI, ensure that /docs, /blog, /static, sidebars.json, siteConfig.js, package.json follow the expected structure.

  2. 要开始迁移,请在正确的文件系统位置运行命令行工具:

# migration command format
npx @docusaurus/migrate migrate <v1 website directory> <desired v2 website directory>

# example
npx @docusaurus/migrate migrate ./v1-website ./v2-website
  1. 要在本地预览你的新网站,请前往 v2 站点目录并启动开发服务器。
cd ./v2-website
npm install
npm start
危险

迁移会 CLI 更新现有文件。 请务必先把它们提交到 git 上!

Options

你可以在使用迁移 CLI 时添加额外参数,来自动把 Markdown 内容和页面也迁移到 v2 版本。 但你大概率仍然需要手动修改才能达到最佳效果。

参数描述
--mdx自动将 Markdown 文件转换为 MDX 格式
--page自动迁移页面
# 参数示例
npx @docusaurus/migrate migrate --mdx --page ./v1-website ./v2-website
危险

页面及 MDX 迁移功能仍处于开发状态。

We recommend you to try to run the pages without these options, commit, and then try to run the migration again with the --page and --mdx options.

这样,你可以通过检查文件变化来修复问题。