1

I have a Firebase project that has started to grow in amount of functions. My functions folder looks something like:

/functions
|--/lib (compiled to js)
|--index.ts (exports each function )
|--/reducers
|----red1.ts
|----red2.ts
|--/listeners
|----list1.ts
|----list2.ts
|--package.json

The problem I'm facing, is that the same code is deployed for each function. So for this example, I have 4 functions.They run without a problem.But when deployed, each one contains the code for all other functions as well, not just the one they use. This makes deployed take a long time and it's messy as well.

I would like a way to maybe split them into separate folders that deploy individually and contain only the code they require. Would something like this be possible?

Ciubakka
  • 33
  • 2
  • 8
  • Is it possible? Yes. Should you? Not in the way you describe. This is because if you have code that is shared between the functions they can get out of sync with each other. If you updated `methodA` in some file, how do you know which functions use that file and need to be redeployed? You are better off just deploying the duplicated code and then optimising how that code is loaded. Look up "optimising firebase functions cold start time" for various strategies. – samthecodingman Jun 18 '21 at 17:52
  • I can group functions by the purpose they serve. Sure, I would have some duplicated code but I still think it's better than having every function contain the code for all functions. Cause I don't have issues with cold start, I have issues with deployment and code management. So how could I do this? – Ciubakka Jun 19 '21 at 09:46
  • Does this [Firebase Functions as Self-contained Packages](https://stackoverflow.com/a/65535935/3068190) approach help? This was intended to allow you to deploy functions with different node versions, but I don't see why you couldn't adapt it for what you are trying to do. – samthecodingman Jun 19 '21 at 15:01
  • This was one of the reasons I switched languages, not the primary one though. With both go and java, each function is a separate entity. I switched to go, it did bring in a whole new batch of weird "features" though... I'm hoping that's mostly because they are still actively building in the language support. – Cadet Jun 20 '21 at 13:30

0 Answers0