@firemono/nx
Version:
Nx plugin for Firebase development with proper architecture - Functions as Nx apps building to dist, live reloading, and auto-persisted emulator data
196 lines (143 loc) โข 5.6 kB
Markdown
# @firemono/nx
> Nx plugin for Firebase development with proper architecture
An Nx plugin that integrates Firebase projects into your Nx workspace with the **correct architecture** - Firebase Functions as proper Nx applications building to `dist/`, live reloading during development, and auto-persisted emulator data.
## โจ Features
- ๐ **Functions as Nx Apps**: Firebase Functions are real Nx applications with proper TypeScript, ESLint, and testing setup
- ๐ **Builds to dist/**: Functions build to workspace `dist/` directory following Nx conventions
- ๐ **Live Reloading**: Watch mode rebuilds functions automatically during development
- ๐พ **Auto-Persisted Data**: Emulator data automatically saved/restored between sessions
- ๐๏ธ **esbuild**: Fast builds with `@nx/esbuild` executor
- ๐งน **Clean Architecture**: No copying, Firebase reads directly from dist
- ๐ง **Full Nx Integration**: Lint, test, build, and deploy with Nx tooling
## ๐ฆ Installation
```bash
# Install the plugin
npm install -D @firemono/nx
# Or with yarn
yarn add -D @firemono/nx
```
## ๐ Quick Start
### 1. Initialize Firebase Project
First, create your Firebase project configuration:
```bash
mkdir my-firebase-init
cd my-firebase-init
firebase init
# Select: Functions, Firestore, Hosting, Emulators
# Choose TypeScript for functions
cd ..
```
### 2. Generate Nx Firebase Project
```bash
nx generate @firemono/nx:init --name my-app --directory apps/my-app --initDirectory ./my-firebase-init
```
This creates:
- `apps/my-app/functions/` - Nx Functions app (builds to `dist/my-app/functions`)
- `apps/my-app/firebase/` - Firebase project (uses functions from dist)
### 3. Start Development
```bash
# Start with live reloading
nx dev my-app-firebase
# Or build manually
nx build my-app-firebase
# Deploy to Firebase
nx deploy my-app-firebase
```
## ๐๏ธ Architecture
```
apps/
โโโ my-app/
โ โโโ functions/ # Nx Functions app
โ โ โโโ src/index.ts # Source code
โ โ โโโ project.json # โ builds to dist/my-app/functions
โ โโโ firebase/ # Firebase project
โ โโโ firebase.json # โ source: "../../../dist/my-app/functions"
โ โโโ emulator-data/ # Auto-persisted data
โโโ dist/
โโโ my-app/
โโโ functions/ # Firebase reads from here!
```
## ๐ฏ Benefits
- **โ
Proper Nx Apps**: Functions follow Nx conventions with full tooling support
- **โ
Workspace dist/**: All builds go to workspace `dist/` directory
- **โ
No File Copying**: Firebase reads directly from dist (no build step copying)
- **โ
Live Development**: Watch mode + Firebase emulators = instant feedback
- **โ
Auto-Persistence**: Emulator data saved/restored automatically
- **โ
TypeScript First**: Full TypeScript support with proper configurations
- **โ
Fast Builds**: esbuild for lightning-fast function builds
## ๐ Generator Options
```bash
nx generate @firemono/nx:init [options]
```
| Option | Description | Required |
|--------|-------------|----------|
| `--name` | Name of the Firebase project | โ
|
| `--directory` | Directory where project should be created | โ
|
| `--initDirectory` | Path to Firebase init directory | โ
|
### Example
```bash
nx generate @firemono/nx:init \
--name ecommerce \
--directory apps/ecommerce \
--initDirectory ./firebase-init-ecommerce
```
Creates:
- `apps/ecommerce/functions/` (Nx app building to `dist/ecommerce/functions`)
- `apps/ecommerce/firebase/` (Firebase project using dist functions)
## ๐ง Generated Commands
Each Firebase project gets these Nx targets:
```bash
# Development with live reloading
nx dev my-app-firebase
# Build functions and prepare for deployment
nx build my-app-firebase
# Deploy to Firebase
nx deploy my-app-firebase
nx deploy-functions my-app-firebase
# Emulator management
nx emulators:start my-app-firebase
nx emulators:debug my-app-firebase
nx emulators:stop my-app-firebase
# Data management (auto-handled during dev)
nx data:export my-app-firebase
nx data:import my-app-firebase
```
## ๐ Development Workflow
1. **Start Development**:
```bash
nx dev my-app-firebase
```
This runs:
- `nx build my-app-functions --watch` (rebuilds on changes)
- Firebase emulators with auto-import/export
2. **Edit Functions**:
- Edit `apps/my-app/functions/src/index.ts`
- Functions rebuild automatically
- Firebase sees changes instantly
3. **Data Persists**:
- Stop emulators (Ctrl+C) โ data auto-exported
- Restart โ data auto-imported
- Zero manual data management
## ๐ท๏ธ Project Tags
Generated projects include semantic tags:
- `type:firebase` - Firebase infrastructure project
- `scope:{name}` - Groups related projects
- `platform:firebase` - Firebase deployment platform
- `feature:{detected}` - Auto-detected Firebase features
Use tags for targeted operations:
```bash
# Test all Firebase projects
nx run-many --target=test --projects=tag:type:firebase
# Build all projects in scope
nx run-many --target=build --projects=tag:scope:my-app
```
## ๐ Requirements
- Nx workspace (v20.0.0+)
- Node.js 18+
- Firebase CLI (for deployment and emulators)
## ๐ค Contributing
Contributions welcome! Please read the [contributing guide](https://github.com/johannesnormannjensen/firemono/blob/main/CONTRIBUTING.md).
## ๐ License
MIT ยฉ [Johannes Firemono](https://github.com/johannesnormannjensen/firemono)
---
**Built with โค๏ธ for the Nx and Firebase communities**