如何避免Firebase警告我正在使用开发版本? [英] How to avoid Firebase warning that I’m using the development build?

查看:61
本文介绍了如何避免Firebase警告我正在使用开发版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用firebase auth 包为我的ReactJS应用创建登录页面.

I'm making a login page for my ReactJS app using the firebase auth package.

我已经将 auth 包导入了我的全局firebase文件中:

I have imported the auth package in my global firebase file:

import firebase from 'firebase/app';
import 'firebase/firestore';
import 'firebase/auth';

const config = {
    apiKey: "xxx",
    authDomain: "xxx",
    databaseURL: "xxx",
    projectId: "xxx",
    storageBucket: "xxx",
    messagingSenderId: "xxx"
};

export default firebase.initializeApp(config);

现在在我的 LoginComponent 中,我需要访问类 FacebookAuthProvider ,该类是 firebase.auth 命名空间的一部分.为了访问该类,我导入了 auth 命名空间.

Now in my LoginComponent I need to access the classFacebookAuthProvider which is part of the firebase.auth namespace. In order to get access to this class I import the auth namespace.

import React, { Component } from 'react';
import { auth } from 'firebase';

class Login extends Component {
    provider = new auth.FacebookAuthProvider();

由于最后一次导入,我在控制台中收到以下警告:

Because of this last import I’m getting the following warning in my console:

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>';

在阅读了许多文档和代码之后,我仍然无法弄清如何在访问 FacebookAuthProvider 类的同时消除此警告.

After going through so much documentation and code I still haven’t been able to figure out how to get rid of this warning while being able to access the FacebookAuthProvider class.

第二个问题:目前我是否正在使用完整的firebase开发SDK?我只导入了 auth 命名空间,对吗?

A second question: Am I actually using the full firebase development SDK at this moment? I only imported the auth namespace, right??

推荐答案

您的登录组件正在导入完整的Firebase SDK,这就是导致该警告的原因.您将只需要导入所需的零件.如果已经加载了相同的文件,则捆绑程序或浏览器将对重复数据删除.

Your login component is importing the full Firebase SDK, which is what leads to that warning. You will have to import only the parts that you need. Your bundler or browser will dedupe if the same file has been loaded already.

更改此:

import React, { Component } from 'react';
import { auth } from 'firebase';

对此:

import React, { Component } from 'react';
import firebase from 'firebase/app';
import 'firebase/auth';

这篇关于如何避免Firebase警告我正在使用开发版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆