angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

angularfire2 importing unused firebase modules

Open AdamJo opened this issue 9 years ago • 4 comments

Version info

Angular: 2.4.8

Firebase: 3.6.10

AngularFire: 2.0.0-beta.8

operating system: Windows 10

How to reproduce these conditions

Currently I am only importing the following modules and still getting all of firebase along with it:

api.service.ts
-----------
import { 
AngularFireDatabase,
FirebaseListObservable,
FirebaseObjectObservable
} from 'angularfire2';

app.imports.ts
----------
import { AngularFireModule } from 'angularfire2';

Is there a way to only import firebase.database via angularfire2 and not get auth, storage, and messaging?

Debug output

capture

Expected behavior

Actual behavior

AdamJo avatar Feb 28 '17 05:02 AdamJo

The imports in the AngularFire2 source use from 'firebase' which will resolve to node_modules/firebase/firebase-browser.js (via the browser entry point in the package.json). The content of firebase-browser.js is:

/**
 *  Firebase libraries for browser - npm package.
 *
 * Usage:
 *
 *   firebase = require('firebase');
 */
var firebase = require('./app');
require('./auth');
require('./database');
require('./storage');
require('./messaging');
module.exports = firebase;

So all of the modules you listed are bundled.

Modifying the AngularFire2 source to import the modules individually would be painful, as the individual modules - like firebase-database.js - don't have associated TypeScript .d.ts files.

It should, however, be possible for you to configure your bundler to include only the modules you think are relevant. I think this is more of a bundler issue than an AngularFire2 issue.

cartant avatar Feb 28 '17 08:02 cartant

@cartant Interesting, thanks for the advice.

As a test, I went into firebase-browser.js and was able to comment out storage and messaging without breaking anything but ran into issues leaving out auth (a facebook provider message error) even though I am only using firebase/app and firebase/database in my application. Obviously, this isn't the best solution since I'd have to do this every time I update firebase.

I'll mess around with some other solutions using Webpack to see if I can get rid of auth (an extra 115kb) and post my solution here in case anyone else wants to try it.

AdamJo avatar Feb 28 '17 20:02 AdamJo

@AdamJo @cartant This is one of my chief concerns before the release candidate. See #854 for the details we plan on fixing this.

davideast avatar Mar 12 '17 20:03 davideast

@davideast Glad to hear and thanks for the reply. I'll go ahead and close this issue since you got the other one open.

AdamJo avatar Mar 12 '17 21:03 AdamJo