firebase / firebase/firebase-admin-node

[FR] Bundle size

Offen
#1,426 14 Kommentare 7 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
needs-triage type: feature request
Vorherrschende Sprache
TypeScript
Sterne
1.7k
Forks
419
Ø Merge
3 T. 10 Std.
Gemergte PRs (30 T.)
16

Beschreibung

**Is your feature request related to a problem? Please describe.**
When using `firebase-admin` on AWS lambda it adds a big blog to the bundle size. We are using `esbuild` to bundle our sources written in TS, and bundling the admin sdk adds an extra of 5.7MB, minified 2.8MB. This is far from optimal, because the bundle should be as small as possible for better cold-start performance. The code looks like this:

```js
import * as admin from "firebase-admin";

const app = admin.initializeApp();
console.log("app :>> ", app);

const firestore = app.firestore();
console.log("firestore :>> ", firestore);
```

**Describe the solution you'd like**
Make it possible to load or install only the parts of the SDK that are really needed (like the new version of the js client sdk => https://github.com/firebase/firebase-js-sdk)

**Describe alternatives you've considered**
I tried to add only parts of SDK we need, e.g.

```js
import { initializeApp } from "firebase-admin/lib/firebase-namespace";

const app = initializeApp();
console.log("app :>> ", app);

const firestore = app.firestore();
console.log("firestore :>> ", firestore);
```

but this gives the same bundle size and it does not work, even when compiling with `tsc`: When running via `node main.js` it gives this:

```bash
/some/path/main.js:6
var app = (0, firebase_namespace_1.initializeApp)();
^

TypeError: (0 , firebase_namespace_1.initializeApp) is not a function
```

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne mit dem TypeScript-Beispiel, das firebase-admin und den alternativen Einstiegspunkt firebase-admin/lib/firebase-namespace importiert, reproduziere dann das gemeldete Bundle mit esbuild und untersuche die generierte main.js. Die Aufgabe ist abgeschlossen, wenn das SDK nur die benötigten Teile laden kann und das resultierende Bundle deutlich kleiner ist, ohne die Initialisierung oder die Verwendung von Firestore zu beeinträchtigen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
aws, nodejs, typescript
Bereich
build-system, cloud, performance
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.