Skip to content
This repository has been archived by the owner on Feb 4, 2018. It is now read-only.

jthegedus/firebase-functions-babel-example

Repository files navigation

THIS REPO HAS BEEN MOVED

This example has been merged into my blog-examples repo. This repo will no longer be updated.


Firebase Functions with Babel config to target the correct Execution Environment

styled with prettier

Use Babel to target the correct execution environment for Cloud Functions for Firebase and use modern languages features (ES6+) to develop.

Here is the accompanying Medium post;

TLDR;

Develop your Cloud Functions in a different directory to the default ./functions directory. I suggest ./firebaseFunctions. Then use @babel/core, @babel/cli and babel/preset-env with some npm scripts to compile to the Cloud Functions server runtime of NodeJS v6.11.5. The output directory is the default ./functions directory which is created on compilation in the deploy step (yarn deploy).

Installation

git clone https://github.com/jthegedus/firebase-functions-babel-example
cd firebase-functions-babel-example
yarn install

Login to the Firebase CLI

If you are using a global install of the firebase-tools CLI then skip to the Deploy to Firebase step.

Login to the local firebase-tools:

yarn login

Local Testing

yarn serve

NB: Our code must run through the compilation step each time it is changed, even when hosted locally. We therefore lose the ability of firebase serve reserving our function when code is changed, as it's changed in another file and dir.

Deploy to Firebase

yarn deploy

N.B.: You will need to connect the project to your Firebase project. Edit the name in .firebaserc

A note on Code Compatibility

Everything was tested on Ubuntu 17.04. If you wish for Windows native support please submit an issue so we can work on a Windows branch. Please report any macOS errors as I do not have access to a device to test. My development environment can be found here.

About

Use ES6+ features with Babel to target the correct environment for Cloud Functions for Firebase

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published