【问题标题】:Firebase function for emulator, ignore on deploy模拟器的 Firebase 功能,部署时忽略
【发布时间】:2021-03-22 21:03:32
【问题描述】:

当我运行 firebase deploy 时,我正在寻找一种排除某些 firebase 功能的方法。但是我想在运行模拟器时保留这些功能。

当我使用颤振驱动程序执行集成测试,并且我的应用程序连接到模拟器时,我需要一些方法来从我的测试脚本更改 firestore 中的数据。我可以使用 http 包调用的 firebase 函数将是一个很好的方法。但这些仿真器特定功能不得部署到生产环境中。我知道我可以使用--only 标志,当我运行firebase deploy 来指定所有功能时,我想部署。但这有点麻烦。我不想每次都写下我要部署的所有功能的名称。

我知道,我的 firebase.json 中的函数键可以与“忽略”字段一起使用。但我无法弄清楚它是如何工作的。在 src/index.ts 文件中导出的所有函数(编译到 lib/src/index.js)都已部署。那么忽略键是如何工作的呢?我试着这样使用它:

{
    "functions": {
    "source": "functions",
    "ignore": [
        "**/node_modules/**",
      "**/src/emulator/**"
    ]
  }
}

但这会导致部署错误。

【问题讨论】:

    标签: typescript firebase google-cloud-functions firebase-tools


    【解决方案1】:

    我找到了解决问题的方法。通过将其放入我的 index.ts

    var emulator = undefined;
    if(process.env.FUNCTIONS_EMULATOR) {
        emulator = emulatorFunction;
    }
    
    export {emulator};
    

    当我运行 firebase deploy 时,我在模拟器中使用的功能没有部署到生产环境中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-14
      • 2022-12-14
      • 2018-12-15
      • 2019-10-28
      • 1970-01-01
      • 1970-01-01
      • 2020-07-09
      • 2022-10-07
      相关资源
      最近更新 更多