Setup Firebase with turbo repo
Goal
Create a Firebase deployment setup with:
- Single Firebase project
- Two environments (development and production)
- Multiple hosting sites in
apps/*folders - Cloud Functions in
apps/apifolder - Streamlined development and CI/CD using GitHub Actions
Challenges & Solutions
1. Project Structure Configuration
Challenge: Maintaining single source of truth for Firebase configuration files.
Solution:
- Keep
firebase.jsonand.firebasercin root folder as templates - Copy these files to specific app folders during deployment
2. Firebase Cloud Functions Setup
Challenge: Firebase Cloud Functions lacks native monorepo support and doesn't work with pnpm's workspace:* protocol (Issue #653).
Local development
Configure firebase.json:
{
"functions": {
"source": "apps/api/dist" // IMPORTANT! Points to TypeScript output
}
}
Deployment Process
- Create
firebase-for-deploy.jsonin apps/api withsource": "." - Process
apps/api/package.json:
Copy to
apps/api/distBuild all dependencies
Convert workspace dependencies:
// Before
{
"dependencies": {
"core": "workspace:*"
}
}
// After
{
"dependencies": {
"core": "file:./core"
}
}Remove
devDependenciesCopy
firebase-for-deploy.jsontodist/firebase.json
3. Firebase Hosting Configuration
Project Structure:
my-turborepo/
├── .firebaserc # Root template
├── firebase.json # Root template
├── apps/
│ ├── listen/
│ │ ├── .firebaserc # Copied for deployment
│ │ ├── firebase.json # Copied for deployment
│ │ └── src/
│ └── admin/
│ ├── .firebaserc # Copied for deployment
│ ├── firebase.json # Copied for deployment
│ └── src/
Important: In firebase.json, use relative paths for public directory:
{
"hosting": [
{
"public": "dist" // Relative to apps/* folder
}
]
}
GitHub Actions Configuration:
- name: Copy Firebase configs
run: |
cp .firebaserc apps/admin/.firebaserc
cp firebase.json apps/admin/firebase.json
Setup Instructions
1. Firebase Project Setup
- Create new Firebase project
- Set up project aliases:
devfor development/testingproductionfor live environment
2. GitHub Actions Configuration
Environment Secrets
- Repository Secrets:
FIREBASE_SERVICE_ACCOUNT_MY_WORLD_DEV: Service account for dev environmentFIREBASE_SERVICE_ACCOUNT_SWORLD_PROD: Service account for production environment
- Environment Secrets (per environment):
VITE_API_KEYVITE_APP_IDVITE_AUTH_DOMAINVITE_MEASUREMENT_IDVITE_MESSAGING_SENDER_IDVITE_PROJECT_IDVITE_STORAGE_BUCKET
3. Deployment Strategy
- Independent deployments per site
- Triggered by changes in
mainbranch - Uses Firebase Hosting preview channels for pre-deployment testing
- Cloud Functions deployment handled via custom script (
apps/api/scripts/prepare-deploy.ts). The deployment script avoids external dependencies for better long-term maintainability.