Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am developing with Firebase Cloud Functions and testing on local emulators. I am using Typescript as my language. However, whenever I update my code and hit save, the changes do not reflect in the emulator. I would always have to stop and re-run the emulator. Is there a way where I could achieve this without having to stop and re-run?

like image 351
Ziyad Avatar asked Sep 16 '25 21:09

Ziyad


1 Answers

Typescript supports a configuration file called tsconfig.json. In that file you can configure the compiler, define code formatting rules and more importantly for you, provide it with information about the TS files in your project. You have it watch the files for changes then you can use the 'watch' flag: tsc --watch inside your package scripts.

Script:

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

A common tsconfig.json file:

{
"compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "declaration": false,
    "noImplicitAny": false,
    "removeComments": true,
    "noLib": false
},
"include": [
    "**/*"
],
"exclude": [
    "node_modules",
    "**/*.spec.ts"
]}
like image 118
DIGI Byte Avatar answered Sep 19 '25 01:09

DIGI Byte