simondotm / nx-firebase

Firebase plugin for Nx Monorepos
https://www.npmjs.com/package/@simondotm/nx-firebase
MIT License
175 stars 31 forks source link

Feature request: Deploy only one function from a multiple functions app #160

Closed pikilon closed 8 months ago

pikilon commented 8 months ago

Current behavior

Expected behavior

simondotm commented 8 months ago

ah, good scenario, thanks @pikilon . I might have to think about how best to handle this in plugin.

The good news is that you can do this with the Firebase CLI.

Each nx-firebase function app is effectively a codebase, so the magic spell you need to deploy just one function from a codebase collection is:

npx firebase deploy --only functions:<codebase>:function-name

where <codebase> is whatever name you gave your nx-firebase:function project.

simondotm commented 8 months ago

An alternative solution is to generate another nx-firebase:function project and move your single function into it.

I havent yet decided in my own workflow if it makes sense to have one nx-firebase:function project per exported firebase cloud function definition. 🤔

This approach does have the benefit that esbuild tree shakes the compiled output to only contain code for that one function being exported, which depending on your project complexity could mean faster cold starts etc.

Plus since one app, one function, then nx deploy my-function does deploy just that one cloud function.

Downside is a lot more boiler plate and code fragments in the workspace since there are more app projects around.

But I tend to have very little code in my firebase function main.ts and just import what I need from an Nx Typescript library.

simondotm commented 8 months ago

UPDATE: Actually the plugin can in fact do this already, even if you have multiple exports in your nx-firebase:functions project, it's similar syntax:

npx nx deploy <codebase> --only functions:<codebase>:function-name

As above, where <codebase> is whatever name you gave your nx-firebase:function project.

pikilon commented 8 months ago

npx firebase deploy --only functions::function-name

Thank you very much, I will use it. I will try to help you as a tester until I know enough to help you with the code. Until then here you have 4 coffees https://Ko-fi.com/home/coffeeshop?txid=137771cf-a7c6-42ad-9d80-24fe744c5282&mode=public&img=ogiboughtsomeone