【问题标题】:how to deploy react app with github gh-pages如何使用 github gh-pages 部署 React 应用程序
【发布时间】:2020-08-04 18:48:22
【问题描述】:

我在没有使用样板 create-react-app 的情况下创建了 react 应用程序。我想用 git hub 部署它。我可以部署它吗?如果是,任何人都可以建议步骤吗?

【问题讨论】:

标签: reactjs github deployment web-deployment


【解决方案1】:

假设您已安装 gh-pages 软件包并且您知道如何部署 index.html,例如,将其添加到您的 package.json 脚本中:

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

然后运行npm run deploy

看看这篇关于它的深入文章,如果你卡住了,或者给这个答案留下一些问题

https://dev.to/yuribenjamin/how-to-deploy-react-app-in-github-pages-2a1f

【讨论】:

  • 当我尝试这种方式时,我收到错误 ENOENT: no such file or directory, stat 'D:\Other\projects\TreeStructure\build'。
  • gh-pages -d build 在此命令中,build 应该是构建 react 应用程序的文件夹的名称,可以是 /dist/build。尝试运行npm run build 并查看出现了哪个新文件夹。如果是dist,请尝试使其成为gh-pages -d dist
  • 非常感谢。你是对的,将 build 更改为 dist 有效。我收到消息已发布,但是当我在浏览器中尝试 url 时没有显示任何内容。
  • 我不确定如何真正调试它。您可以在几个小时后尝试访问该网站,尝试以隐身模式(没有缓存和 cookie 等),或者尝试查看 GitHub 页面在哪里显示其部署错误?
猜你喜欢
  • 2018-12-09
  • 1970-01-01
  • 2022-01-12
  • 1970-01-01
  • 2020-08-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-20
相关资源
最近更新 更多