Reputation: 171
I'm building a react project using create-react-app and am trying to figure out how to deploy my code to my hosting server on Siteground.
Does anyone know the best way to do this? Do I import my build folder through FTP? Can I automate the process through GitHub?
Thanks in advance!
Upvotes: 17
Views: 28195
Reputation: 19
I have problem deploying on siteground as well the simple solution is to have a git repo for your build and setup your public_html folder on siteground to track that git repo.
make sure to also create
.htaccess
with the content something like this
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]
If you don't have that your routing won't work
Also remember to go Tools->Speed->Caching and flush the cache if you have deployed otherwise before
Upvotes: 1
Reputation: 2069
If you are using create-react-app
, then you could do:
npm run build
or yarn build
build
folder as a result of the previous point.htaccess
file with the following content:
<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>
Check this great article for more info :)
Hope it helps!
Upvotes: 2
Reputation: 270
I just uploaded my create-react-app to siteground with FileZilla here is the step by step:
npm run build
go to cPanel
scroll down and find FTP Accounts
public_html
configure FTP client
and under manual setting you've got what you need to connnectsiteManager
then new site
host
(in filezilla) === FTP server
(in sitiGround), port
set it as siteground port , protocol and encryption leave it as defaultLogon Type
set as normal , user
=== FTP user
(siteGround) and password
the one you've used to create that FTP userconnect
and paste the content of yourApp/build
(from the left side that is your PC) to (the folder at the right hand side) that is your public_html in siteGround
That's it! go to your website and check, the react app should be displayed there
here is the source of this procedure https://www.siteground.com/tutorials/ftp/ Here they use quick connect for fileZilla though, I have more than one site so siteManager is cleaner and stores your credentials for next time
Upvotes: 5
Reputation: 649
npm run build
or yarn build
Builds the app for production to the build folder
.
It correctly bundles React in production mode and optimizes the build for the best performance.
npm run build
creates a build directory with a production build of your app. Set up your favorite HTTP server so that a visitor to your site is served index.html, and requests to static paths like /static/js/main.<hash>.js
are served with the contents of the /static/js/main.<hash>.js
file.
source: create-react-app
Upvotes: 6
Reputation: 1957
Usually there are guided strategies from host vendors.
Example:
Otherwise you'll have to manage it by yourself, registering a custom build script that acts with:
npm run build
And then move the build folder. If you use Maven you can manage the entire build with plugins like:
Upvotes: 2
Reputation: 5651
Per the create-react-app
docs, you run npm run build
and basically just take the output and FTP it to your web server.
However your question is very broad -- you could automate through GitHub or some other tool, but that's really going to beg opinionated responses on StackOverflow (which isn't the right forum for those kinds of questions).
Upvotes: 13