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?
1 Answer
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"
]}