0

Is there a way to have a Firebase/Google cloud function with this kind of architecture with cli command (firebase deploy --only functions) ?

Expected:

.
└── functions/
    ├── function_using_axios/
    │   ├── node_modules/
    │   ├── package.json
    │   └── index.js
    └── function_using_moment/
        ├── node_modules/
        ├── package.json
        └── index.js

Currently, my archi look like this:

.
└── functions/
    ├── node_modules/
    ├── package.json
    ├── index.js
    ├── function_using_axios.js
    └── function_using_moment.js

The fact is, i have a lot of useless packages dependencies for some functions. And it increase cold start time.

I know this is possible with the web UI.

WEB UI Exemple:

List List web UI

One package for one Function Function with his own package


My Current Archi see on WEB UI, one Package for all functions: One package for all functions

Any idea ?

Thanks.

1 Answers1

1

When deploying through Firebase there can only be a single index.js file, although gcloud may any different in this respect.

To ensure you only load the dependencies that each function needs, move the require for each dependency into the functions that need it:

exports.usageStats = functions.https.onRequest((request, response) => {
  const module = require('your-dependency');
  // ...
});

Also see:

  • the Firebase documentation on organizing functions, which shows a way to have the functions over multiple files (although you'll still need to import/export them all in index.js).
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807