I am playing with firebase functions. Works fine when deploying to firebase server using command firebase deploy --only functions
. However, I would like to test my functions locally before deploy to server of course. What I see running firebase serve is that the functions "deployed" locally have not the latest changes I did in indext.ts - are running the last builded version, which are in index.js.
My question is, How do I manual build my firebase functions project to test them locally with latest changes?
Should firebase serve
autobuild the project before deploy it locally? For me, it sounds like a bug.
When using firebase serve , your app interacts with an emulated backend for your Hosting content and config (and optionally functions) but your real backend for all other project resources. Note: By running this command with the --only hosting flag, you're only emulating your Hosting content and config.
The firebase init command creates a firebase. json configuration file in the root of your project directory. The firebase. json file is required to deploy assets with the Firebase CLI because it specifies which files and settings from your project directory are deployed to your Firebase project.
firebase serve
doesn't seem to be running npm build
. But if you look inside functions/package.json
, you can see there is already a serve
script there that performs npm run build && firebase serve --only functions
. So if you just do:
cd functions
npm run serve
You can build and serve without having to do two separate commands.
If you want to reload the changes to your TypeScript when running firebase serve
or firebase functions:shell
, all you have to do is build your project again using npm script that was created for you when you initialized the project (see package.json):
cd functions
npm run build
This will transpile your TypeScript to JavaScript, and the changes to the JavaScript will get picked up by the emulator automatically.
Also, if you are a more advanced TypeScript user, you can run tsc --watch
to automatically compile TS to JS when source files change on disk. You can read more about that in this blog.
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