How to Deploy a React App to Firebase Hosting

Deploying React app by creating a project from the Firebase console.

Prerequisites

The following needs to be installed globally create-react-app and firebase-tools.

npm install -g create-react-app
npm install -g firebase-tools

Steps for creating a React app and deploying it to Firebase.

  1. Create a new React project
create-react-app myapp
create-react-app command in CMD

2. Go to the Firebase console and click on create a project.

Firebase console screenshot

3. Enter a unique name for your project. This name will be your hosted URL, and click on the next button.

Example: myapp-unique.web.app

Firebase project creation console step 1

4. Press continue.

Firebase project creation console step 2

5. Configure google analytics and press create project button.

Firebase project creation console step 3

6. Your project has been created successfully now head back to your command prompt.

Firebase project creation successful.

7. Open the command prompt in the root of your project and enter the following commands.

firebase login

You will be redirected to the browser. Log into the same account in which you created the project.

Firebase login CMD
Firebase login success on CMD.
firebase init
Select Firebase hosting in CMD

8. Scroll down using the arrow keys and press the spacebar to select the Hosting option and then press enter.

Now press enter to select the existing project.

Select an existing project from Firebase.

9. Scroll down to select your project and press enter.

Firebase hosting

10. Now write build to be used as your public directory and press enter.

Write Yes to configure it as a single-page app.

Write No for not setting automatic builds and deploy with GitHub.

Now finally run following command.

npm run build && firebase deploy
firebase hosting command

Your project has been deployed successfully.

Now if you go to this link in the browser you can view the project.

Congratulations you have deployed your React App on Firebase. If you have any questions, feel free to reach me on LinkedIn. I’d love to hear if this helped anyone.

Leave a Reply

Your email address will not be published. Required fields are marked *