[英]Can I deploy my ReactJS app on a regular host?
I've seen many guides where people teach you how to deploy your react app on services like digital ocean, heroku, GitHub Pages, aws.我看过很多指南,人们教你如何在服务上部署你的 React 应用程序,例如数字海洋、heroku、GitHub 页面、aws。 But I'm wondering if I can deploy my React app (create-react-app) which consists of only front end in a host service like 000webhost or Ipage?但我想知道我是否可以部署我的 React 应用程序 (create-react-app),它只包含主机服务中的前端,如 000webhost 或 Ipage? Because a person wants me to design a website, and he says that he already has a domain name and a host service in lpage.因为一个人要我设计一个网站,他说他在lpage已经有域名和主机服务了。
I use webpack to bundle my react app. 我使用webpack捆绑我的反应应用程序。 So at the end react app will be: 所以最后反应应用将是:
Regarding .css there are several better ways how to include, but you can likely start with simple setup as mentioned above. 关于.css,有几种更好的方法可以包含,但你可以从上面提到的简单设置开始。
So you just put these 3 things on your server, and your app is available at index.html. 所以你只需将这三件事放在你的服务器上,你的应用程序就可以在index.html上找到。
PS Don't know what is Ipage, and haven't worked with create-react-app. PS不知道什么是Ipage,并且没有使用create-react-app。
Run ' npm run build
' from your command line folder where your project is located. 从项目所在的命令行文件夹中运行“ npm run build
”。 Copy files from the 'build' folder that is created and upload them in your host's root folder or equivalent. 从创建的“build”文件夹中复制文件,并将其上传到主机的根文件夹或同等文件夹中。 Takes less than a minute. 不到一分钟。
This may be quite old, but, i have accomplished the React deploy on a regular web hosting on subdirectory;这可能已经很老了,但是,我已经在子目录上的常规 web 主机上完成了 React 部署;
A few things that must be changed or included必须更改或包含的一些内容
1 - Set the "homepage" on package.json - "homepage":"https://example.com"
or in my case "homepage":"https://example.com/myApp"
1 - 在 package.json 上设置“主页” - "homepage":"https://example.com"
或者在我的例子中是"homepage":"https://example.com/myApp"
2 - Set basename on router file - <Router basename={'/myApp'}></Router>
OR <BrowserRouter basename={'/myApp'}></BrowserRouter>
2 - 在路由器文件上设置 basename - <Router basename={'/myApp'}></Router>
或<BrowserRouter basename={'/myApp'}></BrowserRouter>
3 - Set the .htaccess file as - 3 - 将 .htaccess 文件设置为 -
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /myApp/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /myApp/index.html [L]
</IfModule>
4 - build - npm run build
4 - 构建 - npm run build
5 - Now i can access my React App on https://example.com/myApp
5 - 现在我可以在https://example.com/myApp
上访问我的 React 应用程序
source: google and https://www.fullstacktutorials.com/deploy-react-app-subdirectory-10.html资料来源:谷歌和https://www.fullstacktutorials.com/deploy-react-app-subdirectory-10.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.