article Saturday 27 April 2024

Deploy a React app using Firebase Hosting

Author

Step 1

Make sure your app is running locally by going into the apps directory and running npm start from your terminal.

npm start
https://firebasestor...

Step 2

Go to console.firebase.google.com and create a project

https://firebasestor...

Step 3

Install the Firebase CLI tools by running the command below in your terminal

npm install -g firebase-tools

Step 4

Login to firebase running firebase login from your terminal.

firebase login

Your terminal will now look like this.

https://firebasestor...

Your browser will popup with a user login window so you can choose the account. You must use the same account that you used when you set your project up in step 2

https://firebasestor...

Step 5

Initialize Firebase in your project by running the command below in your terminal

firebase init

When you see the firebase services menu choose "Hosting" with the arrow keys (up/down) and space bar to select. Hit enter

https://firebasestor...

Step 6

Select your project by using the arrow keys and then hit enter

https://firebasestor...

Step 7

When it asks what you want the public directory to be answer ./

https://firebasestor...

When it asks if you want to configure as a single page app answer Y

https://firebasestor...

Firebase Initialization is complete will be the next message you should see.

https://firebasestor...

Step 8

Add a deploy name and value to the package.json of your react app.

"deploy": "npm run build && firebase deploy",
https://firebasestor...

Step 9

You are now ready to deploy. Run the command below in your terminal.

npm run deploy
https://firebasestor...

Follow the Hosting URL to go to your fully deployed and live site in the browser.

https://firebasestor...

Troubleshooting

Problem: Firebase init > project not showing in list

Get your project id from settings

https://firebasestor...

Make the CLI recognize and use your project by running the command below in your terminal

firebase use --add react-fun-ee3ee
https://firebasestor...