[英]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.