【问题标题】:How to automatically update the code in firebase cloud functions on local emulator on save with Typescript如何在使用 Typescript 保存时自动更新本地模拟器上的 Firebase 云函数中的代码
【发布时间】:2021-09-17 23:06:39
【问题描述】:

我正在使用 Firebase Cloud Functions 进行开发并在本地模拟器上进行测试。我使用 Typescript 作为我的语言。 但是,每当我更新我的代码并点击保存时,这些更改都不会反映在模拟器中。我总是不得不停止并重新运行模拟器。 有没有一种方法可以实现这一点而无需停止并重新运行?

【问题讨论】:

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


    【解决方案1】:

    Typescript 支持名为 tsconfig.json 的配置文件。在该文件中,您可以配置编译器,定义代码格式化规则,更重要的是,为您提供有关项目中 TS 文件的信息。你让它监视文件的变化,然后你可以在你的包脚本中使用'watch'标志:tsc --watch

    脚本:

    "scripts": {
       "serve": "npm run build -- --watch | firebase emulators:start --only functions",
       ...
    }`
    

    一个普通的 tsconfig.json 文件:

    {
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "declaration": false,
        "noImplicitAny": false,
        "removeComments": true,
        "noLib": false
    },
    "include": [
        "**/*"
    ],
    "exclude": [
        "node_modules",
        "**/*.spec.ts"
    ]}
    

    【讨论】:

      猜你喜欢
      • 2019-10-24
      • 2020-07-03
      • 2021-02-26
      • 2020-12-03
      • 1970-01-01
      • 2022-01-24
      • 2020-10-26
      • 2020-11-09
      相关资源
      最近更新 更多