Skip to main content
RapidDev - Software Development Agency
firebase-tutorial

How to Deploy a Firebase Hosting Site

To deploy a Firebase Hosting site, install the Firebase CLI, run firebase init hosting to configure your project, build your app, and run firebase deploy --only hosting to push files to the CDN. Firebase automatically provisions an SSL certificate and serves your site from a global CDN. Use preview channels to test changes before going live.

What you'll learn

  • How to install and authenticate the Firebase CLI
  • How to initialize Firebase Hosting for your project
  • How to deploy your site to Firebase's global CDN
  • How to use preview channels to test before going live
Book a free consultation
4.9Clutch rating
600+Happy partners
17+Countries served
190+Team members
Beginner6 min read10-15 minFirebase (Spark and Blaze plans), Firebase CLI v13+March 2026RapidDev Engineering Team
TL;DR

To deploy a Firebase Hosting site, install the Firebase CLI, run firebase init hosting to configure your project, build your app, and run firebase deploy --only hosting to push files to the CDN. Firebase automatically provisions an SSL certificate and serves your site from a global CDN. Use preview channels to test changes before going live.

Deploying Your First Site to Firebase Hosting

Firebase Hosting provides fast, secure hosting for web apps with automatic SSL and a global CDN. This tutorial walks through the full deployment process from installing the CLI to publishing your site, including preview channels for staging and custom domain setup basics.

Prerequisites

  • A Firebase project created in the Firebase Console
  • Node.js 18 or later installed on your machine
  • A built web application with static files (HTML, CSS, JS) or a framework build output
  • A Google account linked to your Firebase project

Step-by-step guide

1

Install the Firebase CLI and log in

Install the Firebase CLI globally using npm. Once installed, authenticate with your Google account by running firebase login. This opens a browser window where you grant the CLI access to your Firebase projects. After successful login, the CLI stores your credentials locally so you do not need to log in again on the same machine.

typescript
1npm install -g firebase-tools
2firebase login

Expected result: The CLI prints 'Success! Logged in as your-email@gmail.com'.

2

Initialize Firebase Hosting in your project

Navigate to your project directory and run firebase init hosting. The CLI prompts you to select an existing Firebase project or create a new one. When asked for the public directory, enter the folder where your built files live (typically 'dist' for Vite, 'build' for Create React App, or 'out' for Next.js static export). Answer 'Yes' to configure as a single-page app if you use client-side routing, which creates a rewrite rule sending all routes to index.html.

typescript
1cd my-project
2firebase init hosting
3
4# When prompted:
5# ? What do you want to use as your public directory? dist
6# ? Configure as a single-page app? Yes
7# ? Set up automatic builds with GitHub? No

Expected result: A firebase.json file appears in your project root with hosting configuration.

3

Configure firebase.json for your framework

Open firebase.json and verify the hosting configuration matches your build output. The public field points to your build directory. Add headers for caching static assets, and ensure the rewrites array has a catch-all rule if you use client-side routing. For frameworks like React Router or Vue Router, the SPA rewrite ensures deep links work correctly instead of returning 404 errors.

typescript
1// firebase.json
2{
3 "hosting": {
4 "public": "dist",
5 "ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
6 "rewrites": [
7 {
8 "source": "**",
9 "destination": "/index.html"
10 }
11 ],
12 "headers": [
13 {
14 "source": "**/*.@(js|css|svg|png|jpg|webp)",
15 "headers": [
16 {
17 "key": "Cache-Control",
18 "value": "public, max-age=31536000, immutable"
19 }
20 ]
21 }
22 ]
23 }
24}

Expected result: firebase.json is properly configured with your public directory, SPA rewrite, and caching headers.

4

Build your application

Run your framework's build command to generate production-ready files in the public directory you specified. This step compiles, minifies, and bundles your code. Make sure the output directory matches the public field in firebase.json. If you are using environment variables, confirm they are set before building.

typescript
1npm run build

Expected result: The build output directory contains index.html and bundled JS/CSS files.

5

Deploy to Firebase Hosting

Run firebase deploy --only hosting to upload your built files to Firebase's CDN. The CLI compresses and uploads files, then prints the live URL. Your site is immediately available at your-project.web.app and your-project.firebaseapp.com with automatic SSL. The deploy process takes 30 to 60 seconds for a typical site.

typescript
1firebase deploy --only hosting
2
3# Output:
4# Deploy complete!
5# Hosting URL: https://your-project.web.app

Expected result: The CLI shows 'Deploy complete!' with your live hosting URL.

6

Test changes with a preview channel

Before deploying to production, use preview channels to create a temporary URL for testing. Run firebase hosting:channel:deploy with a channel name to create an isolated preview. Preview URLs expire after 7 days by default. Share the preview URL with teammates for review before promoting to production. This avoids deploying untested changes to your live site.

typescript
1firebase hosting:channel:deploy staging
2
3# Output:
4# Channel URL: https://your-project--staging-abc123.web.app
5# (expires in 7 days)
6
7# To customize expiry:
8firebase hosting:channel:deploy staging --expires 3d

Expected result: A temporary preview URL is created where you can test your changes independently from the live site.

Complete working example

firebase.json
1{
2 "hosting": {
3 "public": "dist",
4 "ignore": [
5 "firebase.json",
6 "**/.*",
7 "**/node_modules/**"
8 ],
9 "rewrites": [
10 {
11 "source": "**",
12 "destination": "/index.html"
13 }
14 ],
15 "headers": [
16 {
17 "source": "**/*.@(js|css|svg|png|jpg|webp|woff2)",
18 "headers": [
19 {
20 "key": "Cache-Control",
21 "value": "public, max-age=31536000, immutable"
22 }
23 ]
24 },
25 {
26 "source": "/index.html",
27 "headers": [
28 {
29 "key": "Cache-Control",
30 "value": "no-cache, no-store, must-revalidate"
31 }
32 ]
33 }
34 ],
35 "cleanUrls": true,
36 "trailingSlash": false
37 }
38}

Common mistakes when deploying a Firebase Hosting Site

Why it's a problem: Setting the wrong public directory, resulting in a blank page or 404 after deploy

How to avoid: Verify firebase.json's public field matches your actual build output directory. Run 'ls' on that directory to confirm index.html exists before deploying.

Why it's a problem: Forgetting to build before deploying, uploading source files instead of compiled output

How to avoid: Always run your build command (npm run build) before firebase deploy. The CLI uploads whatever is in the public directory, including stale files from a previous build.

Why it's a problem: Not configuring SPA rewrites, causing 404 errors on client-side routes when users refresh

How to avoid: Add a catch-all rewrite rule that sends all unmatched paths to /index.html. Without this, Firebase returns 404 for any path that does not correspond to an actual file.

Why it's a problem: Deploying all services when you only want to update hosting, accidentally overwriting Cloud Functions

How to avoid: Always use firebase deploy --only hosting to deploy just the static site. Running firebase deploy without --only deploys everything configured in firebase.json.

Best practices

  • Always use --only hosting flag to deploy hosting independently from other Firebase services
  • Set Cache-Control to immutable with long max-age for hashed static assets, and no-cache for index.html
  • Use preview channels to test changes before deploying to production
  • Check firebase.json into version control so your team shares the same configuration
  • Add .firebase/ to .gitignore to avoid committing local cache files
  • Use the cleanUrls option to serve /about instead of /about.html for cleaner URLs
  • Set up GitHub Actions or CI to automate builds and deploys on push to main

Still stuck?

Copy one of these prompts to get a personalized, step-by-step explanation.

ChatGPT Prompt

I want to deploy a React app built with Vite to Firebase Hosting. The build output is in the dist folder and I use React Router for client-side routing. Show me the complete firebase.json configuration and deployment commands.

Firebase Prompt

Set up Firebase Hosting for my Vite React project. The build output directory is dist. Configure SPA rewrites so React Router paths work on refresh. Add caching headers for static assets. Show me the full firebase.json and deployment steps.

Frequently asked questions

Is Firebase Hosting free?

Yes, the Spark free plan includes 10 GB of storage and 360 MB/day of bandwidth. The Blaze plan charges $0.026/GB for storage and $0.15/GB for bandwidth beyond the free quota.

How long does a Firebase Hosting deploy take?

A typical deploy takes 30 to 60 seconds. The CLI compresses and uploads files, then invalidates the CDN cache. Larger sites with many files may take slightly longer.

Can I deploy to Firebase Hosting without the CLI?

Yes, you can use GitHub Actions with the Firebase Hosting GitHub integration for automatic deploys on push. Firebase also supports the Hosting REST API for programmatic deployments.

How do I roll back a bad deploy?

Go to the Firebase Console, navigate to Hosting, and click the three-dot menu on a previous deploy to roll back. You can also redeploy a previous version by checking out the old code and running firebase deploy again.

Why does my site show a blank page after deploying?

The most common cause is a wrong public directory in firebase.json. Verify the public field points to your build output (dist, build, or out) and that the directory contains an index.html file.

Can I use Firebase Hosting with server-side rendering?

Firebase App Hosting (GA since April 2025) supports SSR frameworks like Next.js and Angular with automatic GitHub CI/CD. Traditional Firebase Hosting is for static sites and SPAs only.

Can RapidDev help configure Firebase Hosting for complex deployment setups?

Yes, RapidDev's engineering team can help set up Firebase Hosting with custom domains, CI/CD pipelines, and multi-environment configurations tailored to your project.

RapidDev

Talk to an Expert

Our team has built 600+ apps. Get personalized help with your project.

Book a free consultation

Need help with your project?

Our experts have built 600+ apps and can accelerate your development. Book a free consultation — no strings attached.

Book a free consultation

We put the rapid in RapidDev

Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We'll discuss your project and provide a custom quote at no cost.