最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览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"
}
发布评论

评论列表(0)

  1. 暂无评论