Giter Site home page Giter Site logo

hackfred / firebase-functions-typescript-starter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from robisim74/firebase-functions-typescript-starter

0.0 0.0 0.0 129 KB

Create & test Firebase Cloud Functions in TypeScript

License: MIT License

JavaScript 12.86% TypeScript 87.14%

firebase-functions-typescript-starter's Introduction

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 

4 Building

Development

The following command:

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

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

firebase-functions-typescript-starter's People

Contributors

robisim74 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.