/firebase-tutorials

How to host SPA with Firebase hosting?

Host your Single Page Application with Firebase Hosting. Follow our step-by-step guide to set up, build, and deploy your SPA quickly and easily.

Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free No-Code consultation

How to host SPA with Firebase hosting?

 

Step 1: Prerequisites

Before starting, ensure you have the following:

  • Node.js and npm installed.
  • A Firebase account.
  • Your Single Page Application (SPA) ready to be deployed.
  • Firebase CLI installed.

If you haven't installed Firebase CLI, you can do so using npm:

npm install -g firebase-tools

 

Step 2: Initialize Firebase in Your Project

Create a Firebase project through the Firebase Console if you haven't already. Once you have a project, initialize Firebase in your local project by opening a terminal and executing:

firebase login

Then, navigate to your project's root directory and run:

firebase init

You'll be prompted with several options:

  • Select "Hosting: Configure and deploy Firebase Hosting sites."
  • Choose your Firebase project you want to deploy.
  • Set the public directory. This should point to your directory where the build output of your SPA resides. For instance, if you are using a framework like React or Angular, this might be build or dist.
  • Decide whether or not to configure as a single-page app, say "Yes" to rewrite all URLs to /index.html.

 

Step 3: Build Your SPA

Before deploying, ensure your SPA is ready and built for production. Depending on the framework you used, this step may vary. For instance, with React:

Navigate to your project directory and run:

npm run build

This will create an optimized bundle in the build directory.

For Angular:

ng build --prod

This creates a build in the dist/project-name directory.

 

Step 4: Deploy to Firebase Hosting

Now that your SPA is built and Firebase is initialized, run the deploy command:

firebase deploy

Firebase CLI will take care of the rest. It uploads your files to Firebase Hosting and provides you with a deployment URL.

 

Step 5: View Your Deployed Application

After a successful deployment, you'll see a URL in the terminal output. Open this URL in your browser to view your hosted SPA.

 

Step 6: Manage Hosting via Firebase Console

You can manage your hosting and view more details about your deployments in the Firebase Console:

  • Go to the Firebase Console.
  • Select the project you have deployed.
  • Click on "Hosting" to see your deployed site, manage versions, and set up custom domains if needed.

 

This completes the step-by-step guide to hosting a Single Page Application on Firebase Hosting. Make sure to verify everything is functioning correctly after deployment.

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

Client trust and success are our top priorities

When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.

Rapid Dev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with. They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

CPO, Praction - Arkady Sokolov

May 2, 2023

Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost. He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Co-Founder, Arc - Donald Muir

Dec 27, 2022

Rapid Dev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space. They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Co-CEO, Grantify - Mat Westergreen-Thorne

Oct 15, 2022

Rapid Dev is an excellent developer for no-code and low-code solutions.
We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Co-Founder, Church Real Estate Marketplace - Emmanuel Brown

May 1, 2024 

Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 
This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Production Manager, Media Production Company - Samantha Fekete

Sep 23, 2022