Skip to content

robisim74/firebase-functions-typescript-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 ES bundle
    • tsconfig.json TypeScript compiler options
    • .mocharc.json Mocha options
    • .eslintrc.json ESLint configuration
  • .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 ES 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 

4 Building

Development

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

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. Node.js

    The engine in package.json is set to Node.js 16

  2. ES Modules

    Node.js 16 supports ES Modules: so you have "type": "module" in package.json, format: 'es' in rollup.config.js and tsconfig.js used by tsc compiler targets ES2021 with ES2020 modules

  3. 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

License

MIT

Releases

No releases published

Packages

No packages published