如何在静态服务器上托管 ReactJS 项目 [英] How to host a ReactJS project on a static server

查看:44
本文介绍了如何在静态服务器上托管 ReactJS 项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我构建了一个 React 应用程序,它在本地服务器上运行良好.但是,当我运行 npm run build 时,该进程似乎正确执行(创建 build 文件夹,其中包含捆绑的 js 文件和 index.html 文件),但是当我在浏览器中打开 index.html 时,它什么也没呈现.我读了一些关于使用node.js的静态服务器,问题是,我支付了hostgator并使用静态服务器,我需要支付一个月的费用,几乎是我为一年支付的金额,有一些方法可以在服务器上运行它没有节点,apache 等?(因为项目已经完成了)...谢谢大家欣赏!

I have a built a React application and it runs fine from the local server. However, when I run npm run build, the process appears to execute correctly (creates build folder, which contains the bundled js file and the index.html file), but when I open index.html in my browser it renders nothing. I read something about static server to use node.js, the problem is, Im paying hostgator and to use a static server I need to pay for month almost the amount that Im paying for year, there is some way to run it on a server without node, apache etc? (because the project is already done)... Thanks guys appreciate!

推荐答案

在你放置构建文件的地方(最后截图)

On the place you are putting your build file (screenshot at last)

您需要创建.htacces文件

将此内容复制并粘贴到 .htacces

Copy and paste this content in that .htacces

Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]

它现在应该可以工作了.

It should probably work now.

[注意:] 尝试使用 Cpanel 中的 file 选项创建它,一旦创建,编辑 .htacess 文件并粘贴上面的代码片段(第 3 和第 4图像).

[Note:] Try creating it using file option in your Cpanel and once it is created, edit .htacess file and paste the above code snippet (3rd and 4th Image).

类似的东西

.htacess 文件在哪里

添加新文件

点击 .htacess 文件,然后选择编辑进行编辑

这篇关于如何在静态服务器上托管 ReactJS 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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