gpt4 book ai didi

reactjs - 为什么我的 create-react-app 显示 README.md,而不是 index.html?

转载 作者:行者123 更新时间:2023-12-03 13:41:06 26 4
gpt4 key购买 nike

为什么我的 create-react-app 显示 README.md,而不是 index.html?

我已经运行了 npm run build -> yarn run deploy,多次检查了文件结构并阅读了 gh-pages 文档。找不到任何其他有相同问题的线程。

谢谢。

最佳答案

您可以查看documentation来自 create-react-app 关于此问题。

将主页添加到 package.json

打开 package.json 并为您的项目添加主页字段:

"homepage": "https://myusername.github.io/my-app",

或者 GitHub 用户页面:

"homepage": "https://myusername.github.io",

Create React App 使用主页字段来确定构建的 HTML 文件中的根 URL。

安装 gh-pages 并将部署添加到 package.json 中的脚本

现在,每当您运行 npm run build 时,您都会看到一份备忘单,其中包含有关如何部署到 GitHub Pages 的说明。

发布于https://myusername.github.io/my-app ,运行:

npm install --save gh-pages

或者你可以使用 yarn :

yarn 添加 gh-pages在 package.json 中添加以下脚本:

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

预部署脚本将在部署运行之前自动运行。

如果您要部署到 GitHub 用户页面而不是项目页面,则需要进行两项额外的修改:

首先,将存储库的源分支更改为除 master 之外的任何分支。此外,调整您的 package.json 脚本以将部署推送到 master:

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

通过运行 npm run deploy 部署站点

然后运行:

npm run deploy

第 4 步:确保您的项目设置使用 gh-pages最后,确保 GitHub 项目设置中的 GitHub Pages 选项设置为使用 gh-pages 分支:

关于reactjs - 为什么我的 create-react-app 显示 README.md,而不是 index.html?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47351598/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com