Home > Back-end >  Deploy Firebase Functions with different dependencies
Deploy Firebase Functions with different dependencies

Time:07-06

I group Firebase Cloud Functions into different subject areas. Each function is developed separately in an individual .ts file (I use TypeScript). Some of those functions rely on external libraries and everything is specified in the package.json.

FunctionA > LibX, LibY
FunctionB > LibZ
package.json includes LibX, LibY and LibZ

My question is when the function is deployed to Firebase, will ALL dependencies specified in package.json be included with EACH function, i.e. FunctionA will include all LibX, LibY and LibZ? Or, Firebase is smart enough to package ONLY the required libraries for the function in deployment (Function A will include only LibX and LibY) I ask because I want to ensure the deployment size each function will be minimized, as this will impact the cold start time.

Someone told me that the only way to do that is to create DIFFERENT package.json to include only right number of dependencies for different functions. But it's sounds like a bit overkilled. Is that really the only way to make sure just the right number of dependencies for each functions?

CodePudding user response:

All dependencies specified in the package.json will be included in each function you create inside the same folder. Firebase only relies on what you deploy on which for example is NodeJS which has npm as its package manager. The only way to minimize inclusion of unused dependencies on other functions is to have a directory structure on your project and have multiple package.json on each folder.

You could also check my answer on this thread which explains how package.json works.

  • Related