如何以 root 身份更新自定义 GitHub 页面

how to update a custom GitHub Pages with create-react-app as root

你好,我已经在线阅读了很多关于将 gh-pages 与 create-react-app 连接起来的文档。但是大多数指南要么假设人们还没有设置 github 页面,并且 React 应用程序将作为目录托管(即 username.github.io/react-app)而不是homepage/root (username.github.io)。我希望有人能帮助我:

  1. 我有一个 github 页面自定义域的现有存储库。它目前正在托管我使用 gulp 和静态 html/css/js 构建的旧站点,以及一个用于自定义 url.

  2. 的 CNAME 文件
  3. 我在 单独的 repo 中使用 create-react-app 重新设计了一个新网站(它对多个页面使用 react-router)。

  4. 我想用我的新 create-react-app 网站作为根主页覆盖我旧 github 页面网站的内容。

这可能吗?如果是这样,实现这一目标的最佳方法是什么?谢谢

  1. 在现有的 Github 页面应用中,删除 CNAME and/or 删除主分支。删除 master 分支会删除站点,而删除 CNAME 会将自定义域清除回默认 [username].github.io.

  2. 在 create-react-app 中,将 CNAME 添加到 /public 文件夹。

  3. 在 create-react-app 中,添加行 "homepage":"./" to package.json
  4. 在 create-react-app 中,运行 npm run build 然后 运行 gh-pages -d build 构建过程,然后 运行 npm run deploy