Skip to content
Create & test Firebase Cloud Functions in TypeScript
Branch: master
Clone or download
Latest commit c3c9671 Oct 9, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
functions
.firebaserc
.gitignore
CHANGELOG.md Upgrade packages and add an auth function sample Sep 3, 2018
LICENSE
README.md Update docs Jan 15, 2018
firebase.json

README.md

Firebase Functions TypeScript starter

Create & test Firebase Cloud Functions in TypeScript.

This starter allows you to create & test Firebase Cloud Functions in TypeScript.

Get the Changelog.

Contents

1 Project structure

  • 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
  • .firebaserc: Firebase projects

2 Customizing

  1. Update Firebase CLI.

  2. Update .firebaserc with your project-id.

  3. Add your Firebase Functions to index.ts, and create different files for each one.

  4. Update in rollup.config.js file external dependencies with those that actually you use to build the cjs bundle.

  5. Create unit tests in tests folder.

3 Testing

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

4 Building

Development

The following command:

npm run serve:dev
  • starts tsc compiler with watch option
  • starts the emulator firebase serve --only functions

Production

The following command:

npm run build
  • creates lib folder with the file of distribution:
└── functions
    └──lib
        └── index.js

5 Publishing

npm run deploy

6 What it is important to know

  1. commonjs modules

    NodeJs used by Firebase Cloud Functions only supports commonjs modules: so the tsconfig.js used by tsc compiler targets es2015 with commonjs modules

  2. 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.js with es2015 modules.

License

MIT

You can’t perform that action at this time.