Firebase Hosting
Relevant source files
The following files were used as context for generating this wiki page:
- packages/firebase-hosting/src/generators/add/add.impl.ts
- packages/firebase-hosting/README.md
- packages/firebase-hosting/src/generators/add/schema.json
- packages/firebase-hosting/project.json
- packages/firebase-hosting/generators.json
- packages/firebase-hosting/package.json
- packages/firebase-hosting/CHANGELOG.md
The @nx-extend/firebase-hosting plugin enables deployment of static applications to Firebase Hosting. It integrates Firebase configuration and deployment commands directly into the Nx workspace workflow.
The plugin automates the setup of hosting targets, manages firebase.json configurations, and provides executors to handle multi-site hosting environments.
Sources: packages/firebase-hosting/README.md:1-12
Core Features
Firebase Hosting within the nx-extend ecosystem provides the following capabilities:
- Static Site Deployment: Deploys build artifacts to Firebase Hosting environments.
- Automatic Configuration: Generates or updates
firebase.jsonautomatically during setup. - Multi-site Support: Manages multiple hosting targets within a single Firebase project.
- Nx Integration: Maps Firebase deployment commands to Nx targets for consistent task execution.
Sources: packages/firebase-hosting/README.md:7-12, packages/firebase-hosting/src/generators/add/add.impl.ts:40-66
Plugin Architecture and Logic
The plugin operates through two primary mechanisms: Generators and Executors. Generators handle the initial project setup and configuration, while Executors perform the actual deployment tasks.
Initialization Flow
The add generator initializes Firebase Hosting for a specific project. It retrieves the project configuration, updates the Nx project targets, and modifies the workspace firebase.json file.
The generator ensures that every hosted application has a corresponding entry in the global firebase.json file and a deploy target in its local configuration.
Sources: packages/firebase-hosting/src/generators/add/add.impl.ts:14-38, packages/firebase-hosting/generators.json:5-10
Configuration Management
The plugin maintains a firebase.json file at the workspace root. When adding a hosting target, the generator populates the hosting array with site-specific settings.
| Property | Description | Source |
|---|---|---|
target | The unique name of the hosting site. | options.site |
public | The directory containing assets to deploy. | build.options.outputPath |
ignore | Files excluded from deployment. | Static defaults |
rewrites | URL redirection rules. | Static defaults (** to /index.html) |
Sources: packages/firebase-hosting/src/generators/add/add.impl.ts:43-56
{
"hosting": [
{
"target": "my-site",
"public": "dist/apps/my-app",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"rewrites": [{ "source": "**", "destination": "/index.html" }]
}
]
}
Sources: packages/firebase-hosting/src/generators/add/add.impl.ts:44-54
Deployment Execution
The deploy executor invokes the Firebase CLI to upload artifacts. Users can trigger this via nx deploy <project-name>.
Deployment Sequence
Executor Options
The deployment process accepts several parameters to control the target environment and behavior.
| Option | Type | Description |
|---|---|---|
site | string | The site identifier defined in firebase.json. |
project | string | The Firebase Project ID to deploy to. |
identifier | string | The hosting project name in Firebase (uses --site if omitted). |
Sources: packages/firebase-hosting/README.md:33-45, packages/firebase-hosting/src/generators/add/schema.json:16-24
Project Structure
The firebase-hosting package is structured as a standard Nx library.
src/generators: Contains logic for setting up hosting in a workspace.src/executors: Contains implementation for the deployment lifecycle.project.json: Defines the plugin's own build and test targets.package.json: Lists dependencies, including@nx/devkit.
Sources: packages/firebase-hosting/project.json:1-68, packages/firebase-hosting/package.json:1-16
Summary
The Firebase Hosting module streamlines the deployment of static sites in Nx workspaces by bridging the gap between Nx project configurations and the Firebase CLI. It automates the generation of firebase.json and provides a standardized deploy target, supporting complex multi-site architectures while maintaining minimal manual configuration.