How to Upload Rect.js WebApp on Netlify

Netlify is a service that automates builds, deployments and manages your websites. It’s one of the fastest and easiest deployment solutions these days.

Netlify offers a free plan. So first, we will log in to Netlify using any one of the options(Github, Gitlab, Bitbucket, Email) given on the login page.

In this article, I am going to share the steps to deploy ReactJS Projects to Netlify using Github Repository or using local computer files.

So, Let’s start with the steps to deploy:

  • Open the Netlify App by clicking here.
  • Create an account on Netlify.




From Local computer:

  • a.) Make a ReactJS App by create-react-app.
  • b.) Build the app by the commands: “npm run build” OR “yarn run build”.
  • c.) Log in to netlify and click on create a new site/ Add new site button and select Deploy manually.
  • d.) Now Drag and drop the build folder created in the base folder to netlify as shown:



d.)Netlify will start deployment of your site,


  Will give a random Green link after successful Deployment


  • f.) If you make some changes and want to update the site you can go to the deploys tab and select ur site, run the build command again and copy the updated build folder, the site will be deployed in the same URL.



Bingo here is a gotcha (Netlify reload 404 error )



Here's an easy hack:

  • Go to the folder which is published to netlify.
  • Create a new file called netlify.toml
  • Copy and paste the following code:

[[redirects]]
from = "/*"
to = "/index.html"
status = 200


Note here, it doesn't matter if you don't have an index.html page in your web app. This just works.

Cheers, and happy coding.


Another gotcha   


Note if  netlify adds your webapp name in the prefix of base URL
 then one of the possible reasons of getting this might be this 

REACT_APP_BASE_URL=hkms-portal.hackerkernel.com

if you are not using HTTP:// in starting of base URL in your env variable  then Netlify makes if own prefix by HTTP:// and your web app name 

So make sure to add HTTP:// in base URL 

REACT_APP_BASE_URL=http://hkms-portal.hackerkernel.com





Comments

Post a Comment

Popular posts from this blog