🔥 All-Access Pass — $199 USD (Regular $499) · Unlock all 2,836 Astro themes ➔
komal.nakrani
Get All-Access Pass ($199)
ThemesCategoriesDocsBlogTips & TricksPricingGet All-Access Pass ($199)
Deployment••By Komal Nakrani

Deploy Astro to Firebase Hosting in Five Steps

Deploy Astro to Firebase Hosting: firebase init with dist as the public folder, no SPA rewrite, clean URLs, cache headers in firebase.json, and preview channels for PRs.

#Astro#Firebase#Deployment

To deploy Astro to Firebase Hosting, install the Firebase CLI, run firebase init hosting, set the public directory to dist, answer No to the single-page app rewrite, then run npm run build and firebase deploy --only hosting. Firebase serves Astro’s static HTML from its CDN, and firebase.json controls headers, redirects and trailing slashes.

Key Takeaways

  • The public directory is dist, Astro’s build output.
  • Do not enable the “rewrite all URLs to /index.html” option; Astro builds a real file per page.
  • Firebase serves dist/404.html for missing pages automatically.
  • Preview channels give each pull request its own temporary URL.

1. Install the CLI and sign in

# Terminal
npm install --global firebase-tools
firebase login

2. Initialise hosting

# Terminal
firebase init hosting

Answer the prompts:

  • Project: select an existing Firebase project or create one.
  • Public directory: dist
  • Configure as a single-page app: No
  • Set up automatic builds and deploys with GitHub: optional; yes creates GitHub Actions workflows for you.
  • Overwrite dist/index.html: No, if it asks.

This writes firebase.json and .firebaserc. Commit both.

3. Configure firebase.json

{
  "hosting": {
    "public": "dist",
    "ignore": ["firebase.json", "**/.*"],
    "cleanUrls": true,
    "trailingSlash": true,
    "headers": [
      {
        "source": "/_astro/**",
        "headers": [
          { "key": "Cache-Control", "value": "public, max-age=31536000, immutable" }
        ]
      }
    ],
    "redirects": [
      { "source": "/old-blog/:slug", "destination": "/blog/:slug/", "type": 301 }
    ]
  }
}

trailingSlash: true matches Astro’s default directory output, where /about/ is about/index.html. If you set trailingSlash: 'never' and build.format: 'file' in Astro, set Firebase’s trailingSlash to false to match. Our trailing slash tip explains the pairing, and the cache headers tip explains the asset rule.

4. Build and deploy

# Terminal
npm run build
firebase deploy --only hosting

The CLI prints a web.app URL. Add a custom domain under Hosting in the Firebase console, then set site in astro.config.mjs to that domain and redeploy so canonical URLs and the sitemap are correct. Current Astro releases need Node.js 22.23.4 or newer on the machine that builds.

A script keeps the two steps together:

{
  "scripts": {
    "deploy": "astro build && firebase deploy --only hosting"
  }
}

5. Preview channels for pull requests

# Terminal
firebase hosting:channel:deploy pr-42 --expires 7d

Each channel gets its own URL and expires automatically. If you let firebase init set up GitHub, it adds a workflow that deploys a channel for every pull request and comments the URL. Our preview deployments tip covers keeping previews out of search engines.

404 pages

Firebase looks for 404.html in the public directory and serves it with a 404 status for any missing path. Create src/pages/404.astro and Astro writes dist/404.html; see our custom 404 tip.

SSR on Firebase

Firebase Hosting serves static files. On-demand rendering needs a separate backend such as Cloud Run or Firebase App Hosting with the Node adapter, which adds cost and setup. For most content sites, a static build is enough. Compare options in free hosting for Astro and the static deploy docs. Themes from our Astro theme catalog are static, so this five-step setup is all they need.

FAQ

What is the public directory for Astro on Firebase?

dist. That is where astro build writes the site. If you changed outDir in astro.config.mjs, use that folder.

Should I configure Astro as a single-page app on Firebase?

No. Astro builds an HTML file for every route. A rewrite of all URLs to /index.html would serve the home page for every missing path and hide 404 errors.

Why does Firebase add or remove trailing slashes on my Astro site?

The trailingSlash and cleanUrls settings in firebase.json control it. Set trailingSlash: true to match Astro’s default directory output.

Is Firebase Hosting free for Astro sites?

Firebase has a free tier with storage and transfer limits. Check Firebase’s current pricing page for exact numbers.