How to Deploy to Firebase Hosting: Step-by-Step Guide
To deploy to
Firebase Hosting, first install the Firebase CLI, then run firebase init hosting to set up your project. Finally, use firebase deploy to upload your files and publish your site.Syntax
The deployment process uses the Firebase CLI commands:
firebase init hosting: Sets up hosting configuration in your project folder.firebase deploy: Uploads your site files to Firebase and makes them live.
You need to be logged in with firebase login before running these commands.
bash
firebase login firebase init hosting firebase deploy
Example
This example shows how to deploy a simple static website folder named public to Firebase Hosting.
bash
firebase login firebase init hosting # When prompted, select your Firebase project and set 'public' as the public directory firebase deploy
Output
ā Success: Project initialized
ā Hosting URL: https://your-project-id.web.app
ā Deploy complete!
Common Pitfalls
- Not running
firebase loginbefore deploying causes authentication errors. - Choosing the wrong public directory during
firebase init hostingmeans your site files won't upload. - Forgetting to build your app (if using frameworks) before deploying uploads outdated files.
bash
Wrong way: firebase deploy Right way: firebase login firebase deploy
Quick Reference
Remember these key steps for smooth Firebase Hosting deployment:
- Always
firebase loginfirst. - Use
firebase init hostingonce per project folder. - Put your site files in the chosen public directory.
- Run
firebase deployto publish updates.
Key Takeaways
Install Firebase CLI and log in with your Google account before deploying.
Run 'firebase init hosting' once to configure your project for hosting.
Place your website files in the specified public directory.
Use 'firebase deploy' to upload and publish your site.
Always build your app before deploying if using a framework.