为什么我的create-react-app显示README.md,而不显示index.html? [英] Why is my create-react-app showing README.md, not index.html?

查看:251
本文介绍了为什么我的create-react-app显示README.md,而不显示index.html?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Why is my create-react-app showing README.md, not index.html?

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

I've run npm run build -> yarn run deploy, checked the file structure multiple times and read the gh-pages docs. Can't find any other thread with the same issue out there.

谢谢。

推荐答案

您可以从签出文档 create-react-app

You can checkout the documentation from create-react-app regarding this.

将首页添加到package.json

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

Open your package.json and add a homepage field for your project:

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

或对于GitHub用户页面:

or for a GitHub user page:

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

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

Create React App uses the homepage field to determine the root URL in the built HTML file.

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

现在,无论何时运行npm运行构建,您将看到一个备忘单,其中包含有关如何部署到GitHub Pages的说明。

Now, whenever you run npm run build, you will see a cheat sheet with instructions on how to deploy to GitHub Pages.

要在 https://myusername.github.io/my-app ,运行:

npm install --save gh-pages

或者使用yarn:

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

yarn add gh-pages Add the following scripts in your package.json:

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

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

The predeploy script will run automatically before deploy is run.

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

If you are deploying to a GitHub user page instead of a project page you'll need to make two additional modifications:

首先,将存储库的source分支更改为any除master以外的其他分支。
此外,调整您的package.json脚本以将部署推送到主服务器:

First, change your repository's source branch to be any branch other than master. Additionally, tweak your package.json scripts to push deployments to 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分支:

Step 4: Ensure your project’s settings use gh-pages Finally, make sure GitHub Pages option in your GitHub project settings is set to use the gh-pages branch:

这篇关于为什么我的create-react-app显示README.md,而不显示index.html?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆