Serving Firebase Functions locally with the firebase serve command is supposed to enable hot reloading but this doesn't seem to work on windows, even with watchman installed. Is there a better solution aside from running npm build
after each code change?
To enable hot reloading on firebase functions with typescript you can add this 2 commands to your package.json file
"build:watch": "tsc -w"
"serve:watch": "npm run build:watch | firebase emulators:start --only functions",
If you want also to use path aliases feature you will be required to install 2 additional dev packages in order to make it work
npm install --save-dev tsc-alias concurrently
tsc-alias is for replacing alias paths with relative paths after typescript compilation of tsc compiler because the compiler alone can't resolve the alias paths
concurrently is for runing multiple commands concurrently
After installing the 2 packages you will need to add this 2 scripts to your package.json file
"build:watch": "concurrently --kill-others \"tsc -w\" \"tsc-alias -w\"",
"serve:watch": "npm run build:watch | firebase emulators:start --only functions",
Starting of development with hot reload then will be as easy as running only in the terminal
npm run serve:watch
Please Note: I am using this versions of the packages
"firebase-admin": "^10.0.1",
"firebase-functions": "^3.14.1",
"tsc-alias": "^1.5.0",
"typescript": "^4.5.5",
"concurrently": "^7.0.0",
Older or newer versions might introduce some issues with compiling the code
I mixed the 2 answers:
"scripts": {
"serve": "npm run build -- --watch | firebase emulators:start --only functions",
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With