简体   繁体   English

我可以在常规主机上部署我的 ReactJS 应用程序吗?

[英]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: 所以最后反应应用将是:

  • one bundle (rarely more if you use dynamic bundle loading - probably not), that is just a javascript file 一个捆绑(如果你使用动态捆绑加载,可能不会更多),这只是一个javascript文件
  • your index.html that includes this file at the end of body 你的index.html在body的末尾包含了这个文件
  • and your .css that you can set in principle in one file (or separate folder with several files) and include at the top of your index.html 你可以在一个文件中设置的.css(或包含多个文件的单独文件夹),并包含在index.html的顶部

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.

相关问题 我可以将独立的 MERN 应用程序托管/部署为另一个网站的一部分吗? - Can I host/deploy a standalone MERN app as part of another website? 掌握VPS主机技术的人是否可以在全部(或大量)在线提供的VPS主机上部署其NodeJS _ ReactJS应用程序? - Does someone who masters the VPS host technology can deploy its NodeJS _ ReactJS app on all - or a great amount - of VPS host available online? 如果我部署我的 React 应用程序,指向 localhost 的链接是否仍然有效,还是我还需要托管 localhost 应用程序? - If I deploy my react app, will the link to a localhost still be valid, or will I also need to host the localhost app? 如何在reactjs应用程序中使用scss文件? - How can I use an scss file in my reactjs app? Reactjs App我在哪里可以定义我的布局? - Reactjs App Where can I define my Layout? 如何在我的 ReactJS 应用程序中添加倒数计时器 - How can I add Countdown Timer in my ReactJS app 我可以在 reactjs 中使用常规引导吐司吗? - Can I use regular bootstrap toast in reactjs? 为什么我不能在 heroku 上部署我的 React 应用程序? - Why can't i deploy my react app on heroku? 如何将我的下一个 js 应用程序部署到 iis 服务器? - How can I deploy my next js app to iis server? 无法在Google App引擎上部署我的reactjs webpack应用程序 - Cannot deploy my reactjs webpack application on google app engine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM