Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serving Firebase Functions doesn't hot reload on Windows

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?

like image 486
galki Avatar asked Nov 13 '18 12:11

galki


2 Answers

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

like image 165
TatkoBarba Avatar answered Sep 19 '22 14:09

TatkoBarba


I mixed the 2 answers:

"scripts": {
   "serve": "npm run build -- --watch | firebase emulators:start --only functions",
   ...
}
like image 22
Maxime Lechevallier Avatar answered Sep 21 '22 14:09

Maxime Lechevallier