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

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

问题描述

在浏览器中加载应用程序时,它会发出以下警告.所以无法为 prod 创建构建 (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天全站免登陆