Fireship · @fireship
Use TypeScript with Firebase Cloud Functions
Uploaded August 10, 2017 · Length 4:12
Summary
Set up Firebase Cloud Functions with TypeScript and Webpack for easier debugging and maintenance.
- firebase cloud functions
- typescript
- webpack
- javascript
- cloud functions
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
when we write firebase cloud functions
- 0:01
we normally do it in plain JavaScript
- 0:03
but this tends to make them hard to
- 0:05
debug what if we could actually write
- 0:07
them in typescript and also throw on web
- 0:09
pack to make them a little more modular
- 0:11
in this quick lesson I'm going to show
- 0:14
you how to set up your cloud function
- 0:15
environment for typescript and web pack
- 0:17
and then we'll deploy a few cloud
- 0:19
functions to firebase I first want to
- 0:22
point out that there's an article on
- 0:23
medium that was the main inspiration for
- 0:25
this video so I'll add a link to that
- 0:27
the description and if you're brand new
- 0:29
to cloud functions I recommend checking
- 0:30
out any of the blue videos on my channel
- 0:32
which are specifically focused on
- 0:34
firebase cloud functions so to get
- 0:36
started I'm assuming you have an
- 0:37
existing project that you're working on
- 0:39
and you'll bring up the command line and
- 0:41
run firebase and knit functions then
- 0:44
select all the default options during
- 0:46
that project setup this is going to
- 0:48
create a new directory in the root of
- 0:50
the project called functions and that's
- 0:52
an isolated node environment where we
- 0:54
can build our cloud functions so the
- 0:57
next step is to CD into that directory
- 0:59
and then we'll create a new directory
- 1:02
called source and we'll put a file in
- 1:05
there called index TS instead of index j
- 1:08
s then we can go ahead and remove the
- 1:11
index j s file for now web pack will
- 1:14
actually generate the index.js file
- 1:16
automatically based on our underlying
- 1:17
typescript code and that's the file that
- 1:20
actually gets deployed the firebase now
- 1:22
let's open up the package JSON file then
- 1:26
we can install typescript and web pack
- 1:27
and we'll specify them only for that
- 1:30
development environment so your final
- 1:32
node environment should look something
- 1:34
like this
- 1:34
and we can add a TS config file nothing
- 1:38
really special here you can go with the
- 1:40
default options and customize it any way
- 1:42
you want then the last step is to create
- 1:44
the web pack config this will tell web
- 1:47
pack how to compile our type script to a
- 1:49
single index.js file that can be
- 1:51
deployed to firebase check out the link
- 1:54
in the description for more detail on
- 1:55
this code so now we can actually start
- 1:57
building cloud functions we can do this
- 1:59
by creating directories inside the


