3

I'm using firebase functions with typescript similar to this instruction. However, I want to keep all tsc compilation result in a separate build folder, so after tsc my project folder look like this:

myApp
 |__ functions
      |__ src/index.ts
      |__ build/src/index.js

How can I let firebase find build/src/index.js instead of ./index.js? There doesn't seem to be a firebase deploy option for this.

Currently I have to cp build/src/index.js . in my npm scripts but it feels like a hack.

swang
  • 5,157
  • 5
  • 33
  • 55

3 Answers3

4

By default, Firebase looks in the functions/ folder for the source code but you can specify another folder by adding the following lines in firebase.json:

"functions": {
  "source": "another-folder"
}

Reference: https://firebase.google.com/docs/functions/manage-functions

Antony Harfield
  • 850
  • 1
  • 7
  • 16
2

THere's currently no option to specify a different output folder for Functions, like you can for Hosting. So instead of this, you probably need to put your .ts files into a different folder (e.g. myApp/functions_src) and tell tsc to output the compiled versions into myApp/functions by using --outdir ./functions as described here.

Kato
  • 40,352
  • 6
  • 119
  • 149
0

Firebase actually uses the main field from your functions/package.json file, you just have to update it with the correct compiled path:

{
  "main": "build/src/index.js"
}
Will Carle
  • 31
  • 3