如何在 cPanel 上部署 React 应用程序? [英] How to deploy a react app on cPanel?
问题描述
我创建了一个具有以下文件夹结构的 React 应用
I've created a react app with the following folder structure
-公共
--dist
---bundle.js
---styles.css
--index.html
--图像
-服务器
--server.js
-src
--组件
--app.js
-.babelrc
-package.json
-webpack.config.js
-public
--dist
---bundle.js
---styles.css
--index.html
--images
-server
--server.js
-src
--components
--app.js
-.babelrc
-package.json
-webpack.config.js
我想将其上传到 cPanel.那可能吗?我还需要上传 node_modules/文件夹吗?
I want to upload it to cPanel. Is that possible? Would I also need to upload the node_modules/ folder?
这是我的存储库的链接:https://github.com/theoiorga/react-费用化应用
here is a link to my repo: https://github.com/theoiorga/react-expensify-app
推荐答案
step 1:"homepage": ".",
-->在 package.json 文件中添加这个
step 1:"homepage": ".",
-->add this on package.json file
第 2 步:npm run build
--> 这将创建一个构建文件夹.
step 2 : npm run build
--> this will create a build folder.
第 3 步:制作一个 .htaccess,它看起来像这样
step 3 : make a .htaccess it will look like this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
</IfModule>
第 4 步:现在将 build 文件夹中的所有文件以及您的 htaccess 放入所需的域或子域中
step 4 : now take all the files in build folder plus your htaccess and drop them in the desired domain or subdomain
这篇关于如何在 cPanel 上部署 React 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!