george43g/better-firebase-functions/skill
Claude Code and agent skill by george43g/better-firebase-functions
- community
Checking that the SKILL.md file is still in the repository.
Expert knowledge for implementing better-firebase-functions in a Firebase Cloud Functions project. Use this skill when a user wants to: add cold-start optimization to Firebase Functions, set up automatic function discovery and export, configure bundler plugins (esbuild/webpack/rollup) for per-function bundles, migrate from manual imports to BFF's auto-export pattern, or troubleshoot BFF configuration. Covers Gen 1, Gen 2, CJS and ESM setups.
Install
npx vskill@latest install george43g/better-firebase-functions/skillSKILL.md
The same SKILL.md was published earlier as george43g/better-firebase-functions/skill.
better-firebase-functions skill
This skill provides complete knowledge for implementing and configuring better-firebase-functions (BFF) in any Firebase Cloud Functions project.
What BFF does
BFF replaces manual function imports with automatic discovery + cold-start optimization. Without BFF, every function module loads on every cold start. With BFF, only the one module matching the currently-invoked function loads.
Runtime behaviour at a glance:
FUNCTION_TARGET/FUNCTION_NAME/K_SERVICEset → cold-start mode: load one matching module only- None set → deployment mode: load all modules so Firebase CLI can discover triggers
BFF_BUILD_DISCOVERY=1set → build-discovery mode: scan files, return metadata, load zero modules
Installation
Entry point setup
The entry point is the single source of truth for all BFF configuration. Write it once — the bundler plugins inherit it automatically.
CJS (most common)
ESM
Function file structure
Each trigger file exports its trigger as the default export:
Naming rules (default, customizable):
| File path | Firebase function name | |
|---|---|---|
functions/on-create.func.ts | onCreate | |
functions/auth/on-create.func.ts | auth-onCreate | |
functions/http/get-user.func.ts | http-getUser | |
functions/http/api/list-users.func.ts | http-api-listUsers |
Dashes create Firebase function groups, enabling firebase deploy --only functions:auth.
searchGlob convention
The glob must match files as they exist at runtime (after TypeScript compilation):
When bundler plugins are used, BFF automatically expands .js → .{js,ts} so build-time discovery finds TypeScript source files. The runtime glob remains .js.
tsconfig / build setup
Typical tsconfig.json for a Firebase project using BFF:
With outDir: "lib" and rootDir: "src", your firebase.json should point to lib/index.js and package.json#main should be lib/index.js.
Configuration options
All options are optional except __filename and exports.
| Option | Type | Default | Description | |
|---|---|---|---|---|
__filename | string | — | Required. Node's __filename | |
exports | object | — | Required. Node's exports / module.exports | |
functionDirectoryPath | string | './' | Directory of trigger files, relative to entry point | |
searchGlob | string | '**/*.{js,ts}' | Glob matching trigger files at runtime | |
funcNameFromRelPath | function | built-in | Custom name generator: (relPath: string) => string | |
extractTrigger | function | mod?.default | Extract trigger from loaded module | |
__dirname | string | derived from __filename | Override base directory for discovery | |
enableLogger | boolean | false | Log discovery and module-load timing | |
logger | object | console | Custom logger with time, timeEnd, log | |
exportPathMode | boolean | false | Export file paths instead of triggers (debugging) |
Bundler plugin setup (optional, takes optimization further)
Bundler plugins produce one independently bundled file per function. No duplicate config is needed — the plugin executes the entry point in build-discovery mode and inherits all settings.
esbuild (recommended for simplicity)
Add to package.json:
webpack
Rollup
Fallback: manual discovery overrides
If the entry point cannot be executed by tsx at build time, pass overrides manually:
Custom naming functions
If the default funcNameFromRelPathDefault does not fit your structure, pass a custom function. Important: the same function must be used at runtime (in the entry point) and at build time (the plugin inherits it from the entry point automatically).
Common pitfalls
searchGlob targets .ts but runtime compiled output is .js
Symptom: Functions deploy fine but are empty / not registered at runtime.
Fix: Use **/*.func.js (or whatever compiled extension), not .ts, in searchGlob. If using tsx/ts-node in production, .ts is fine.
Custom funcNameFromRelPath in entry point but not in bundler config
This is no longer an issue with the current build-discovery approach — the plugin executes the entry point and inherits the same function. But if you fall back to manual overrides, make sure both sides match.
Gen 2 / Cloud Run: Function 'x' is not defined in the provided module
Cloud Run lowercases service names. BFF canonicalizes both sides before comparing, so this should be handled automatically. If you still see this error:
- Check
FUNCTION_TARGETis being set by the Functions Framework (it takes precedence) - Set
enableLogger: trueand check which name BFF is searching for
Bundler plugin: did not expose __bff_discovery
BFF needs tsx to require the TypeScript entry point at build time. Install it:
Or pass manual overrides as a fallback (see above).
Environment variables (read by BFF)
| Variable | When set | BFF behaviour | |
|---|---|---|---|
FUNCTION_TARGET | Gen 2 / Functions Framework | Load the single module whose derived name matches | |
FUNCTION_NAME | Gen 1, some Gen 2 | Same as above; last path segment extracted if full resource path | |
K_SERVICE | Cloud Run (Gen 2) | Same as above; case-normalized before matching | |
| none of the above | During firebase deploy | Load all modules (deployment mode) | |
BFF_BUILD_DISCOVERY=1 | Set by bundler plugins | Scan files, register discovery metadata, load zero modules |
Verification checklist
Before deploying, verify:
- [ ]
__filenameandexportsare passed toexportFunctions() - [ ]
searchGlobmatches compiled output (.js) unless running TypeScript natively - [ ] Each trigger file has
export default <trigger> - [ ]
functionDirectoryPathis correct relative to the entry point - [ ] If using a bundler plugin: entry point can be required by
tsx, or manual overrides are provided - [ ]
firebase.jsonsourcepoints to the directory containingpackage.jsonfor the functions codebase - [ ]
package.json#mainin the functions directory points to the compiled entry point
Example directory layout
firebase.json:
functions/package.json:
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskill/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/george43g/better-firebase-functions/skill)