angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

Break Angulalfire2 into modules.

Open 0x6368656174 opened this issue 8 years ago • 2 comments

In our application, we do not use Realtime Database, we use Firestore, but Angularfire2 still pulls it in main.bundle.js, which increases its size by 200KB. It would be very nice to somehow break Angularfire2 into modules, so as not to drag unnecessary dependencies.

screen

0x6368656174 avatar Jan 05 '18 12:01 0x6368656174

Hi @0x6368656174! We have a required issue template that is needed to help debug your issue. In your case I would need to know your Firebase, Angular, and AngularFire versions. Also I would need to see your import module code.

AngularFire is broken into modules and each feature module only includes the feature needed. If you are getting the database in your bundle then you are likely importing either AngularFire or Firebase incorrectly.

This code below demonstrates how AngularFire is broken up into modules that pull in the needed dependencies. This is also documented in the quickstart.

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { AngularFireModule } from 'angularfire2';
import { AngularFirestoreModule } from 'angularfire2/firestore';
import { AngularFireAuthModule } from 'angularfire2/auth';
import { environment } from '../environments/environment';

@NgModule({
  imports: [
    BrowserModule,
    AngularFireModule.initializeApp(environment.firebase, 'my-app-name'), // imports firebase/app needed for everything
    AngularFirestoreModule, // imports firebase/firestore, only needed for database features
    AngularFireAuthModule, // imports firebase/auth, only needed for auth features
  ],
  declarations: [ AppComponent ],
  bootstrap: [ AppComponent ]
})
export class AppModule {}

davideast avatar Jan 05 '18 13:01 davideast

Thank you @davideast . Understood. The problem arose in that we use firebase.storage as follows:

import * as firebase from 'firebase';

private _storage: firebase.storage.Storage;
constructor() {
    this._storage = firebase.storage();
}

At the same time, webpak completely imports all of the meat.

While storage is not part of AngularFire2, it is necessary to use it as follows:

import * as firbase from 'firebase/app';
import 'firebase/storage';

private _storage: firebase.storage.Storage;
constructor(private _firebaseApp: FirebaseApp) {
    this._storage = _firebaseApp.storage();
}

0x6368656174 avatar Jan 06 '18 11:01 0x6368656174