【问题标题】:How to let Firebase functions find index.js from another directory?如何让 Firebase 函数从另一个目录中找到 index.js?
【发布时间】:2018-03-23 16:19:24
【问题描述】:

我正在使用带有类似于this instruction 的打字稿的firebase 函数。但是,我想将所有 tsc 编译结果保存在单独的构建文件夹中,所以在 tsc 之后我的项目文件夹如下所示:

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

如何让 firebase 找到 build/src/index.js 而不是 ./index.js?似乎没有针对此的 firebase 部署选项。

目前我必须在我的 npm 脚本中cp build/src/index.js .,但感觉就像是 hack。

【问题讨论】:

    标签: javascript typescript firebase google-cloud-functions


    【解决方案1】:

    默认情况下,Firebase 在 functions/ 文件夹中查找源代码,但您可以通过在 firebase.json 中添加以下行来指定另一个文件夹:

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

    参考:https://firebase.google.com/docs/functions/manage-functions

    【讨论】:

      【解决方案2】:

      目前没有选项可以为 Functions 指定不同的输出文件夹,就像您可以为 Hosting 一样。因此,您可能需要将 .ts 文件放入不同的文件夹(例如 myApp/functions_src),并告诉 tsc 使用 --outdir ./functions 作为 described here 将编译后的版本输出到 myApp/functions

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-09-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-07-01
        • 1970-01-01
        • 2014-06-18
        • 2021-01-18
        相关资源
        最近更新 更多