firebase 只导入所需的包

firebase importing just the required packages

我在我的 Angular 6 应用程序中使用 firebase,当我使用如下导入时,

import { auth, User } from 'firebase';

我在浏览器控制台中收到此警告:

It looks like you're using the development build of the Firebase JS SDK.
When deploying Firebase apps to production, it is advisable to only import
the individual SDK components you intend to use.

For the module builds, these are available in the following manner
(replace <PACKAGE> with the name of a component - i.e. auth, database, etc):

CommonJS Modules:
const firebase = require('firebase/app');
require('firebase/<PACKAGE>');

ES Modules:
import firebase from 'firebase/app';
import 'firebase/<PACKAGE>';

每当我将导入切换为 import * as auth from 'firebase/auth':

根据 danfri86 对此 GitHub 问题的评论 - https://github.com/firebase/angularfire/issues/968 - 您应该执行以下操作:

import firebase from 'firebase/app';
import 'firebase/auth'; // This line is important

export const googleProvider = new firebase.auth.GoogleAuthProvider();

这实际上是警告所说的:

ES Modules:
import firebase from 'firebase/app';
import 'firebase/<PACKAGE>';

我刚刚对其进行了测试,它没有抛出任何错误。