Cloud Functions 的 Firebase 模拟器未更新代码

Cla*_*aus 11 firebase google-cloud-functions

我正在使用以下云功能部署firebase deploy --only functions

export const testFunction = functions.https.onCall((data, context) => {
  return {"data": "hello"};
});
Run Code Online (Sandbox Code Playgroud)

当使用代码从客户端应用程序调用它时

var testFunction = firebase.functions().httpsCallable("testFunction");
      testFunction().then((result) => {
        // Read result of the Cloud Function.
        this.data = result.data;
});
Run Code Online (Sandbox Code Playgroud)

它按预期工作。现在,我想继续开发在本地模拟器上测试它的功能,因此,按照文档,我将此行添加到 Web 应用程序代码中(在函数之前)

firebase.functions().useEmulator("localhost", 5001); // for local simulator
Run Code Online (Sandbox Code Playgroud)

我用以下命令运行本地模拟器:

firebase emulators:start --only functions
Run Code Online (Sandbox Code Playgroud)

如果我现在运行客户端应用程序,我会正确地看到通过本地模拟器而不是远程云函数进行的调用。

问题:如果修改代码,本地函数不会更新。我需要再次运行 firebase deploy 才能看到响应的变化。我怎样才能在本地部署?

小智 14

stackoverflow解决了这个问题。

简而言之:

  • 每次更改代码后,运行npm run build以重新编译代码。

  • 自动编译代码中的每个更改。在文件中更改"build": "tsc"为 ,然后在另一个终端窗口中运行模拟器。"build": "tsc -w"package.json


归档时间:

查看次数:

3182 次

最近记录:

2 年,6 月 前