代码之家  ›  专栏  ›  技术社区  ›  eddyP23

firebase只导入所需的包

  •  1
  • eddyP23  · 技术社区  · 6 年前

    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'

    • 我得到一个不同的错误: export 'GoogleAuthProvider' (imported as 'auth') was not found in 'firebase/auth' (因为我也在使用 GoogleAuthProvider )
    • 这个 auth
    1 回复  |  直到 6 年前
        1
  •  2
  •   camden_kid    6 年前

    根据 丹弗里86 对这个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>';
    

    我刚测试过,没有任何错误。