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 cjs bundle
- tsconfig.json tsc compiler options
- tsconfig-build.json tsc compiler options for production
- src folder for the Functions
- .firebaserc: Firebase projects
-
Update Firebase CLI.
-
Update
.firebasercwith yourproject-id. -
Add your Firebase Functions to
index.ts, and create different files for each one. -
Update in
rollup.config.jsfile external dependencies with those that actually you use to build the cjs bundle. -
Create unit tests in
testsfolder.
The following command runs unit tests using Mocha that are in the tests folder:
npm test For the other supported tests, please refer to the official documentation: Run Functions Locally
The following command:
npm run serve:dev- starts tsc compiler with watch option
- starts the emulator firebase serve --only functions
The following command:
npm run build- creates
libfolder with the file of distribution:
└── functions └──lib └── index.js npm run deploy-
commonjsmodulesNodeJs used by Firebase Cloud Functions only supports commonjs modules: so the
tsconfig.jsused by tsc compiler targets es2015 with commonjs modules -
Bundling with Rollup
Firebase Cloud Functions does 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
Since Rollup requires the es2015 modules, tsc compilation is first performed using
tsconfig-build.jswith es2015 modules.
MIT