在浏览器中加载应用程序时出现Firebase JS SDK警告(Angular v5) [英] Firebase JS SDK warning while load application in browser (angular v5)

查看:67
本文介绍了在浏览器中加载应用程序时出现Firebase JS SDK警告(Angular v5)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在浏览器中加载应用程序时,会发出以下警告.因此无法为产品创建构建( ng build --aot --prod )

When application load in browser, it gives following warning. So unable to create build for prod (ng build --aot --prod)

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

我正在使用以下配置

Angular CLI: 1.5.0
Node: 9.8.0
Angular: 5.1.3

"firebase": "^5.0.4",
"angularfire2": "^5.0.0-rc.10"

请指导我哪里出了错.

推荐答案

没有什么真正的错误,它更多是警告和最佳实践提示.

There is nothing really wrong, it is more a warning and a best practices tip.

Firebase由不同的服务/模块组成,例如实时数据库,Firestore,Auth服务等.

Firebase is composed of different services/modules, e.g. the Real Time Database, Firestore, the Auth service, etc.

在大多数项目中,一个服务并不会使用所有这些服务,因此,该警告表明,与仅通过全局导入来导入所有服务相比,最好仅导入应用程序中真正需要的服务.这样,您的构建将得到优化:生成的构建文件将仅包含所需的Firebase SDK代码,而不会包含未使用的部分.

In the majority of projects one does not use ALL those services and therefore this warning indicates that instead of importing all the services with one global import it is better to only import the services you really need in your application. In such a way, your build will be optimized: the resulting build file(s) will only contain the Firebase SDK code that you need and will not contain the parts that are not used.

请参阅以下文档项目: https://firebase.google.com/docs/web/设置,尤其是显示以下内容的部分:

See this documentation item: https://firebase.google.com/docs/web/setup and in particular the part that says:

如果您使用的是诸如Browserify或webpack之类的捆绑软件,则只需require()您使用的组件.

If you are using a bundler like Browserify or webpack, you can just require() the components that you use.


根据您的评论进行更新:


Update following your comment:

使用import关键字,您应该执行以下操作:

With the import keyword, you should do as follows:

import messaging from 'firebase/messaging';

这篇关于在浏览器中加载应用程序时出现Firebase JS SDK警告(Angular v5)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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