0
0
FirebaseHow-ToBeginner Ā· 3 min read

How to Preview Deployment on Firebase Hosting Quickly

Use the firebase serve --only hosting or firebase hosting:preview command to preview your Firebase Hosting deployment locally. This lets you see your site as it will appear after deployment without publishing it live.
šŸ“

Syntax

The main commands to preview Firebase Hosting are:

  • firebase serve --only hosting: Starts a local server to serve your hosting content.
  • firebase hosting:preview: Builds and previews your hosting site locally with the latest changes.

Both commands require you to be in your Firebase project directory with a valid firebase.json configuration.

bash
firebase serve --only hosting

firebase hosting:preview
šŸ’»

Example

This example shows how to preview your Firebase Hosting site locally before deploying:

  1. Open your terminal and navigate to your Firebase project folder.
  2. Run firebase hosting:preview.
  3. Open the provided local URL (usually http://localhost:5000) in your browser to see your site.
bash
cd my-firebase-project
firebase hosting:preview
Output
āœ” hosting: preview started at http://localhost:5000 āœ” hosting: preview running
āš ļø

Common Pitfalls

Common mistakes when previewing Firebase Hosting include:

  • Not running the command inside the Firebase project folder with firebase.json.
  • Forgetting to build your site (e.g., running npm run build) before preview if you use a build step.
  • Using firebase serve without specifying --only hosting, which may start other emulators you don't need.

Always check the terminal output for errors and ensure your local server URL is correct.

bash
Wrong:
firebase serve

Right:
firebase serve --only hosting
šŸ“Š

Quick Reference

CommandDescription
firebase serve --only hostingStart local server to serve hosting content
firebase hosting:previewBuild and preview hosting site locally
firebase deploy --only hostingDeploy hosting site live to Firebase
npm run buildBuild your site before preview if using a build tool
āœ…

Key Takeaways

Run firebase hosting:preview to see your site locally before deploying.
Always execute preview commands inside your Firebase project folder with firebase.json.
Build your site first if you use a build process to see the latest changes.
Use firebase serve --only hosting to serve hosting content without other emulators.
Check the terminal output for the local URL to open your preview in a browser.