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

2024-01-04

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

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

Thanks.


您可以查看文档 https://create-react-app.dev/docs/deployment from 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 https://myusername.github.io/my-app, run:

npm install --save gh-pages

或者你可以使用纱线:

纱线添加 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 分支:

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

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

随机推荐