简体   繁体   English

如何使用 GitHub 托管我的 React 应用程序?

[英]How can I host my React application using GitHub?

I have created my React project and pushed the complete repo to GitHub using Visual Studio Code.我已经创建了我的 React 项目并使用 Visual Studio Code 将完整的 repo 推送到 GitHub。 How can I make my React project live on server with the help of GitHub?如何在 GitHub 的帮助下使我的 React 项目在服务器上运行?

You need to install GitHub Pages package as a dev-dependency.您需要安装 GitHub Pages 包作为开发依赖项。

cd ./into/your-app-folder
npm install gh-pages --save-dev

Add properties to package.json file.将属性添加到 package.json 文件。

The first property you need to add at the top level homepage, second you must define this as a string and the value will be "https://{your-username}.github.io/{repo-name}" , {repo-name} is the name of the GitHub repository you created it will look like this :您需要在顶级主页添加第一个属性,第二个您必须将其定义为字符串,其值将为 "https://{your-username}.github.io/{repo-name}" , {repo -name} 是您创建的 GitHub 存储库的名称,它将如下所示:

"homepage": "http://joedoe.github.io/his-app"

Second in the existing scripts property you need to add predeploy and deploy.第二个在现有的脚本属性中,您需要添加 predeploy 和 deploy。

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

If you pushed everything already to Github, the last step is deploying.如果您已经将所有内容推送到 Github,那么最后一步就是部署。 One liner:一个班轮:

npm run deploy

With this Github will create a new branch called gh-pages, and will be available online.有了这个,Github 将创建一个名为 gh-pages 的新分支,并将在线提供。 Hope I could help and will work accordingly.希望我能提供帮助,并会相应地工作。

If you stuck, you can look it up on the official docs of React .如果卡住了,可以在React官方文档上查找。 Deployment Documentation of React React 部署文档

Once on a deployment I had some issues with the official documentation, and I had to delete my username from the "homepage" property in order to make it work.在部署时,我遇到了官方文档的一些问题,我必须从“主页”属性中删除我的用户名才能使其正常工作。 Although I suggest you first do by the docs, and if you encounter problems, you might can give a try.虽然我建议你先按照文档做,如果你遇到问题,你可以试一试。

There are several options.有几种选择。 Depends on what you want to do, do you want to deploy for production or just to test your development ?取决于您想做什么,您是要为生产部署还是只是为了测试您的开发?

You have several options to deploy such as Heroku, Netlify, Github pages.您有多种部署选项,例如 Heroku、Netlify、Github 页面。

I can help you with the process of deploying, in addition you can have a look on the different documentations for the solutions listed above.我可以帮助您完成部署过程,此外您可以查看上面列出的解决方案的不同文档。

I personnaly suggest using Netlify, in my opinion realy easy to use.我个人建议使用 Netlify,在我看来它真的很容易使用。

Depends on what you want to achieve.取决于你想要达到的目标。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何设置GitHub Pages来托管我的React App? 其他免费选项? - How can I setup GitHub Pages to host my React App? Other free options? 我们可以在 GitHub 上托管我们的 React 应用程序吗? 如果可以的话,它的工作方式是怎样的? - Can We Host Our React Application on GitHub? If we can do, how the way it's work? 我可以在github页面上托管我的React / redux(客户端和api服务器)项目吗? - Can I host my React/redux (client and api server) project on github pages? 如何在 Github 页面上托管我的 React 应用程序而不会被重定向? - How do I host my React app on Github pages without getting redirected? 如何在我的 React 应用程序中隐藏 api 密钥并在 Github 中托管工作版本 - How could I hide api key in my React app and host the working version in Github 如何在我的系统中运行 github React 本机应用程序? - how can i run a github react native app in my system? 在 github 页面上部署 React 应用程序时,如何将我的源代码上传到 github - How can I upload my source code to github when deploying a React app on github pages 我如何在应用程序中对交换/附件进行“交换”反应? - How can I 'swap' react for react/addons in my application? 我如何在我的树莓派上公开托管我的 React JS 网站 - How can i host my react js website publicly on my raspberry pi 我在哪里以及如何使用小型MS SQL DB托管小型ASP .NETCore + React JS应用程序 - Where and how can I host small ASP .NETCore + React JS application with small MS SQL DB
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM