如何在使用 Typescript 保存时自动更新本地模拟器上 firebase 云函数中的代码

How to automatically update the code in firebase cloud functions on local emulator on save with Typescript

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

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"
]}