Skip to main content

Deploying React project to Firebase utilizing Firestore

· 2 min read
Pranjal Kumar
Software Engineer - Bentley

Deploying with Firebase | Pranjal Blogs: pranjal-barnwal | Pranjal Kumar, Hazaribag Jharkhand | SWE Bentley Systems

Unlock the power of Firebase and Firestore integration to seamlessly deploy your React projects. Streamline your development workflow and harness the scalability of Firebase for efficient deployment.

Before starting with anything make sure you have created your project in FireBase & you have used the same Firebase Config in your `firebase.js` file in your local react project folder

1. Create a build folder using:

npm run build

Building the slug | @pranjal-barnwal | Pranjal Blogs: pranjal-barnwal | Pranjal Kumar, Hazaribag Jharkhand | SWE Bentley Systems

This in turn will create a build folder in the root of your project folder.

Folder hierarchy | @pranjal-barnwal | Pranjal Blogs: pranjal-barnwal | Pranjal Kumar, Hazaribag Jharkhand | SWE Bentley Systems

Basically the build files are optimized for production, where there are no ongoing changes in code every now & then.

2. Install the Firebase CLI Tools using:

npm install -g firebase-tools

Installing the firebase tools | @pranjal-barnwal | Pranjal Blogs: pranjal-barnwal | Pranjal Kumar, Hazaribag Jharkhand | SWE Bentley Systems

`-g` flag is used here to install it globally, so it can be accessed easily from any project.

3. Sign in & initialize

firebase login

Logged into firebase | @pranjal-barnwal | Pranjal Blogs: pranjal-barnwal | Pranjal Kumar, Hazaribag Jharkhand | SWE Bentley Systems

For logging in, you will be redirected to browser window, there you simply have to login using your FireBase credentials.

firebase init

You will be asked loads & loads of questions while in `firebase init` but don't worry, I will guide you here:

Firebase setup initiated | @pranjal-barnwal | Pranjal Blogs: pranjal-barnwal | Pranjal Kumar, Hazaribag Jharkhand | SWE Bentley Systems

  1. Are you ready to proceed?

    Type `y`, since we want to continue.

  2. Which Firebase features do you want to set up for this directory? Press Space to select features, then Enter to confirm your choices.

  3. Here, you need to select all features which you included in your project, it may be, you needed nothing & you are just using it for free Hosting. :) In my case, I used Firestore & Storage both in my project & also needed Hosting so, I'm selecting these 3 using space & then press enter.

    Select the desired option | Pranjal Blogs: pranjal-barnwal | Pranjal Kumar, Hazaribag Jharkhand | SWE Bentley Systems

    Make sure to choose the Firebase Hosting, where Github actions are optional.(Refer green stars on above picture).

    When prompted for Firebase rules and other similar stuff, then go with default options.

    Continue selecting the options | Pranjal Blogs: pranjal-barnwal | Pranjal Kumar, Hazaribag Jharkhand | SWE Bentley Systems

    For choosing public directory, make sure you choose the build folder

    Crosscheck the selection | Pranjal Blogs: pranjal-barnwal | Pranjal Kumar, Hazaribag Jharkhand | SWE Bentley Systems

    Go with these options. Make sure you don't overwrite buid/index.html.

    Select storage rules | Pranjal Blogs: pranjal-barnwal | Pranjal Kumar, Hazaribag Jharkhand | SWE Bentley Systems

    4. Deploying our web app

    firebase deploy

    Building and deploying | Pranjal Blogs: pranjal-barnwal | Pranjal Kumar, Hazaribag Jharkhand | SWE Bentley Systems

    Build completed and deployed successfully | Pranjal Blogs: pranjal-barnwal | Pranjal Kumar, Hazaribag Jharkhand | SWE Bentley Systems

    That's it we're done

    Link for the Deployed application will be in the Terminal