Firebase

How to set up Firebase Hosting with a single-page application (SPA)?

Discover the easy way to set up Firebase Hosting for your spa with our detailed guide, tailored for both newcomers and seasoned developers. Whether just starting out or already an expert, this is for you!

Developer profile skeleton
a developer thinking

Overview

Setting up Firebase Hosting for a single-page application (SPA) isn't too tricky if you follow the steps. First, you'll want to hop into your Firebase project using the Firebase Console. Then, get the Firebase CLI installed so you can kick things off, and make sure to set up your Firebase Hosting. Don't forget to point to your SPA's build directory. After that, you'll need to tweak the URL rewrites in the firebase.json so that all routes point to index.html. This way, client-side routing won't break. Finally, push your app to Firebase Hosting to make it live on either a custom domain or one provided by Firebase.

Get a Free No-Code Consultation
Meet with Will, CEO at Bootstrapped to get a Free No-Code Consultation
Book a Call
Will Hawkins
CEO at Bootstrapped

How to set up Firebase Hosting with a single-page application (SPA)?

Step 1: Install Firebase CLI

First things first, make sure you've got Node.js and npm on your computer. Then, you can install the Firebase CLI using npm:

npm install -g firebase-tools

Step 2: Authenticate and Initialize Firebase

Log in to Firebase with the CLI:

firebase login

Next, go to your project directory and initialize Firebase:

firebase init

During the setup, choose:

  • Hosting: Set up files for Firebase Hosting.
  • Use an existing project: If you already have a Firebase project, pick it.

When asked, give the public directory (usually build or dist) and set it up as a single-page app by saying Yes to redirects.

Step 3: Build Your SPA

Make sure your single-page app is built and ready to go. For example, with React, you might run:

npm run build

Ensure the build output directory matches the public directory you specified during Firebase initialization (like build).

Step 4: Configure Firebase Hosting

Firebase will create a firebase.json file. A typical setup might look like this:

{
  "hosting": {
    "public": "build",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

The rewrites array makes sure all routes go to index.html, which is crucial for SPAs.

Step 5: Deploy to Firebase Hosting

Deploy your app:

firebase deploy

This will upload your built SPA to Firebase Hosting and give you a public URL for your app.

Step 6: Verify Deployment

After deploying, Firebase will give you a link to your hosted app. Visit the URL to make sure everything works as expected. If there are issues, check the build and firebase.json configuration. Tweak as needed.

Explore more Firebase tutorials

Complete Guide to Firebase: Tutorials, Tips, and Best Practices

Explore our Firebase tutorials directory - an essential resource for learning how to create, deploy and manage robust server-side applications with ease and efficiency.

Why are companies choosing Bootstrapped?

40-60%

Faster with no-code

Nocode tools allow us to develop and deploy your new application 40-60% faster than regular app development methods.

90 days

From idea to MVP

Save time, money, and energy with an optimized hiring process. Access a pool of experts who are sourced, vetted, and matched to meet your precise requirements.

1 283 apps

built by our developers

With the Bootstrapped platform, managing projects and developers has never been easier.

hero graphic

Our capabilities

Bootstrapped offers a comprehensive suite of capabilities tailored for startups. Our expertise spans web and mobile app development, utilizing the latest technologies to ensure high performance and scalability. The team excels in creating intuitive user interfaces and seamless user experiences. We employ agile methodologies for flexible and efficient project management, ensuring timely delivery and adaptability to changing requirements. Additionally, Bootstrapped provides continuous support and maintenance, helping startups grow and evolve their digital products. Our services are designed to be affordable and high-quality, making them an ideal partner for new ventures.

Engineered for you

1

Fast Development: Bootstrapped specializes in helping startup founders build web and mobile apps quickly, ensuring a fast go-to-market strategy.

2

Tailored Solutions: The company offers customized app development, adapting to specific business needs and goals, which ensures your app stands out in the competitive market.

3

Expert Team: With a team of experienced developers and designers, Bootstrapped ensures high-quality, reliable, and scalable app solutions.

4

Affordable Pricing: Ideal for startups, Bootstrapped offers cost-effective development services without compromising on quality.

5

Supportive Partnership: Beyond development, Bootstrapped provides ongoing support and consultation, fostering long-term success for your startup.

6

Agile Methodology: Utilizing agile development practices, Bootstrapped ensures flexibility, iterative progress, and swift adaptation to changes, enhancing project success.

Yes, if you can dream it, we can build it.