Create & test Firebase Cloud Functions in TypeScript
This starter allows you to create & test Firebase Cloud Functions in TypeScript.
Get the Changelog.
- functions:
- src folder for the Functions
- index.ts entry point for all your Firebase Functions
- tests folder for the Mocha tests
- package.json npm options
- rollup.config.js Rollup configuration for building the ES bundle
- tsconfig.json TypeScript compiler options
- .mocharc.json Mocha options
- .eslintrc.json ESLint configuration
- src folder for the Functions
- .firebaserc: Firebase projects
-
Update Firebase CLI.
-
Update
.firebaserc
with yourproject-id
. -
Add your Firebase Functions to
index.ts
and create different files for each one. -
Update in
rollup.config.js
file external dependencies with those that actually you use to build the ES bundle. -
Create unit tests in
tests
folder.
The following command runs unit tests using Mocha that are in the tests
folder:
npm test
Start tsc compiler with watch option:
npm run build:dev
Start the emulator firebase emulators:start --only functions
npm run serve:dev
For the other supported emulators, please refer to the official documentation: Run Functions Locally
The following command:
npm run build
creates lib
folder with the file of distribution:
└── functions
└──lib
└── index.js
npm run deploy
-
Node.js
The engine in
package.json
is set to Node.js 16 -
ES Modules
Node.js 16 supports ES Modules: so you have
"type": "module"
inpackage.json
,format: 'es'
inrollup.config.js
andtsconfig.js
used by tsc compiler targets ES2021 with ES2020 modules -
Bundling with Rollup
Firebase Cloud Functions do not require the deployment of a single bundle. In any case the building with Rollup offers some advantages:
- Tree shaking of unused code
- No request for other files at runtime
MIT