javascript - How to let Firebase functions find index.js from another directory? - Stack Overflow

admin2025-04-22  0

I'm using firebase functions with typescript similar to this instruction. However, I want to keep all tsc pilation 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.

I'm using firebase functions with typescript similar to this instruction. However, I want to keep all tsc pilation 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.

Share Improve this question asked Oct 11, 2017 at 21:06 swangswang 5,2595 gold badges36 silver badges58 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 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./docs/functions/manage-functions

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 piled versions into myApp/functions by using --outdir ./functions as described here.

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

{
  "main": "build/src/index.js"
}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745297245a295047.html

最新回复(0)