-
Notifications
You must be signed in to change notification settings - Fork 0
Deployment Guide
Deploy your Firebase React application to Firebase Hosting in minutes.
# 1. Build the app
npm run build
# 2. Login to Firebase (first time only)
firebase login
# 3. Deploy
firebase deployYour app will be live at: https://your-project-id.web.app
npm run devMake sure everything works locally before deploying.
npm run lintFix any errors or warnings.
npm run buildThis creates an optimized build in the dist/ folder.
npm run previewTest the production build locally at http://localhost:4173
firebase loginThis opens your browser for Google authentication.
firebase projects:listCheck if your project is listed.
firebase useShould show your project ID from .firebaserc.
firebase deployThis deploys:
- ✅ Hosting (your React app)
- ✅ Firestore rules
- ✅ Firestore indexes
- ✅ Storage rules
After the first deployment, for code-only updates:
npm run build
firebase deploy --only hostingWhen you update security rules:
firebase deploy --only firestore,storageAfter successful deployment:
✔ Deploy complete!
Project Console: https://console.firebase.google.com/project/your-project-id
Hosting URL: https://your-project-id.web.app
Visit the Hosting URL to see your live app!
# 1. Make changes to your code
# 2. Test locally
npm run dev
# 3. Build
npm run build
# 4. Deploy hosting only
firebase deploy --only hosting# 1. Update firestore.rules or storage.rules
# 2. Test rules in Firebase Console (optional)
# 3. Deploy rules only
firebase deploy --only firestore,storage# 1. Make all changes (code + rules)
# 2. Test locally
# 3. Build
npm run build
# 4. Deploy everything
firebase deploy- Go to Firebase Console → Hosting
- Click "Add custom domain"
- Enter your domain (e.g.,
myapp.com) - Click "Continue"
Firebase will provide a TXT record:
Type: TXT
Name: @
Value: firebase-domain-verification=xxxxxxxxxx
Add this to your domain registrar's DNS settings.
Add these A records to your domain:
Type: A
Name: @
Value: 151.101.1.195
Type: A
Name: @
Value: 151.101.65.195
For www subdomain, add CNAME:
Type: CNAME
Name: www
Value: your-project-id.web.app
Firebase automatically provisions SSL. This takes up to 24 hours.
Create separate Firebase projects for development, staging, and production.
# Add projects
firebase use --add
# Select default (production)
firebase use --add
# Enter project ID and alias "production"
# Add staging
firebase use --add
# Enter staging project ID and alias "staging"Update .firebaserc:
{
"projects": {
"default": "my-app-prod",
"staging": "my-app-staging",
"development": "my-app-dev"
}
}# Deploy to staging
firebase use staging
npm run build
firebase deploy
# Deploy to production
firebase use production
npm run build
firebase deploy- Go to Firebase Console → Hosting
- Click "Release history" tab
- Find the previous version
- Click "⋮" → "Rollback"
firebase hosting:clone SOURCE_SITE_ID:SOURCE_CHANNEL TARGET_SITE_ID:liveCreate .github/workflows/firebase-deploy.yml:
name: Deploy to Firebase
on:
push:
branches: [ main ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
env:
VITE_FIREBASE_API_KEY: ${{ secrets.VITE_FIREBASE_API_KEY }}
VITE_FIREBASE_AUTH_DOMAIN: ${{ secrets.VITE_FIREBASE_AUTH_DOMAIN }}
VITE_FIREBASE_PROJECT_ID: ${{ secrets.VITE_FIREBASE_PROJECT_ID }}
VITE_FIREBASE_STORAGE_BUCKET: ${{ secrets.VITE_FIREBASE_STORAGE_BUCKET }}
VITE_FIREBASE_MESSAGING_SENDER_ID: ${{ secrets.VITE_FIREBASE_MESSAGING_SENDER_ID }}
VITE_FIREBASE_APP_ID: ${{ secrets.VITE_FIREBASE_APP_ID }}
- name: Deploy to Firebase
uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: ${{ secrets.GITHUB_TOKEN }}
firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT }}
channelId: live
projectId: your-project-id- Go to GitHub repo → Settings → Secrets → Actions
- Add all environment variables
- Add
FIREBASE_SERVICE_ACCOUNT:- Go to Firebase Console → Project Settings → Service Accounts
- Click "Generate new private key"
- Copy the JSON content
- Add as GitHub secret
Firebase Hosting automatically compresses files. Vite also minifies in production builds.
Update firebase.json for better caching:
{
"hosting": {
"public": "dist",
"headers": [
{
"source": "**/*.@(jpg|jpeg|gif|png|svg|webp|ico)",
"headers": [
{
"key": "Cache-Control",
"value": "max-age=31536000"
}
]
},
{
"source": "**/*.@(js|css)",
"headers": [
{
"key": "Cache-Control",
"value": "max-age=31536000"
}
]
}
]
}
}After building:
npm run buildVite shows the size of each chunk. Keep bundles small for faster loading.
Firebase Console → Hosting shows:
- Total requests
- Bandwidth usage
- Response times
- Geographic distribution
Firebase Console → Project Settings → Integrations:
- Enable email notifications for quota alerts
- Set budget alerts for free tier limits
firebase login --reauth- Check all environment variables are set in
.env - Run
npm run buildlocally first to see errors - Clear
node_modulesand reinstall
- Check syntax in
firestore.rules - Validate rules in Firebase Console
- Make sure Firestore is initialized in your project
- Clear browser cache (Ctrl + Shift + R)
- Check if deployment was successful
- Verify correct Firebase project:
firebase use
Make sure firebase.json has the rewrite rule:
{
"hosting": {
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}# Firebase commands
firebase login # Login to Firebase
firebase logout # Logout
firebase projects:list # List all projects
firebase use PROJECT_ID # Switch project
firebase deploy # Deploy everything
firebase deploy --only hosting # Deploy only hosting
firebase serve # Test locally with Firebase
firebase hosting:channel:list # List all channels
# Build commands
npm run build # Production build
npm run preview # Preview build locally- ✅ Test locally before every deployment
- ✅ Use staging environment for testing
- ✅ Tag releases in git
- ✅ Monitor usage in Firebase Console
- ✅ Set up alerts for quota limits
- ✅ Use CI/CD for automatic deployments
- ✅ Keep rules updated for security
- ✅ Review deployments regularly
Next: Development Workflow →
Firebase React Template | Made with ❤️ | GitHub | Report Issues
Getting Started
Configuration
Advanced Topics
Deployment
- React 19
- Vite
- Firebase 12
- Redux Toolkit
- React Router