reactjs - 是否可以将非主分支部署到 Github Pages?

标签 reactjs github-pages github-pages-deploy-action

我有一个使用 create-react-app 创建的 React 应用程序,它通过 npm run deploy 部署到 Github Pages使用以下命令:

"scripts": {
    "predeploy": "npm run build",
    "deploy": "gh-pages -d build",

更具体地说,我使用了此处的 Github Pages 步骤:https://www.freecodecamp.org/news/surge-vs-github-pages-deploying-a-create-react-app-project-c0ecbf317089

我从一些非开发 friend 那里得到了有关应用程序不同版本的反馈,因此我希望能够进行更改,将它们推送到分支,然后将该分支部署到主页。然后,如果更改不受欢迎,我可以再次部署 master 分支,而不必通过合并和恢复来弄乱 master 分支。这可能吗?如果可以,我该怎么做?我尝试过"deploy": "gh-pages -b <branch-name> -d build"在脚本中,但无济于事,谷歌似乎没有回答这个特定的问题。 (可能是我在“如何将 React 应用程序部署到 Github Pages”教程的海洋中找不到它,我已经解决了)

存储库,如果需要更多上下文:https://github.com/JayBaileyCS/cultivation-idle

最佳答案

Github 页面和 gh-pages是不同的东西。

gh-pages npm 包是一个帮助程序,可以轻松地使用构建的源代码创建一个(新)分支,然后由 github 使用该分支来托管页面。该目标分支称为 gh-pages默认情况下。

部署不同的源分支

如果您尝试从不同的分支部署源代码,那么您可以简单地执行以下操作:

git checkout <branch-name>
npm run build
npm run deploy

这将使用当前分支中的源来创建或更新 gh-pages分支。


使用不同的分支作为目标

-b <branch-name> gh-pages的一部分命令告诉它将编译后的 html 放入哪个分支。如果您愿意,您还可以告诉 github 提供不同的目标分支 -

来自the documentation :

  • Go to your repository
  • Click settings
  • In the "Code and automation" section of the sidebar, click Pages.
  • Under "GitHub Pages", use the None or Branch drop-down menu and select a publishing source.

发布源允许您选择分支。

您还可以在该分支中选择一个文件夹:

  • Optionally, use the drop-down menu to select a folder for your publishing source.

关于reactjs - 是否可以将非主分支部署到 Github Pages?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71252701/

相关文章:

jekyll - GitHub Pages Jekyll 模板存在问题

javascript - SVG(使用 React Simple Maps)未在移动设备上显示

javascript - 类型错误 : state is not iterable on react and redux

javascript - 从 TabNavigator 内部 View 与 StackNavigator 的导航选项交互

github-pages - 为什么我的仓库名称在我的 github pages 站点中显示为标题?

javascript - 如何在 React 生命周期方法中正确分派(dispatch)操作?

css - 为什么使用hexo发布博客无法加载js和css

html - Jekyll Github 页面如何隐藏帖子

github-pages - 使用 github actions 和 github-pages-deploy-action 时,github 页面出现问题?