在浏览器中加载应用程序时 Firebase JS SDK 发出警告(角度 v5)

标签 firebase angular5 angularfire

当应用程序在浏览器中加载时,它会发出以下警告。因此无法为产品创建构建(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"

请指导我哪里错了。

最佳答案

没有什么真正的错误,这更多的是一个警告和一个最佳实践提示。

Firebase 由不同的服务/模块组成,例如实时数据库、Firestore、身份验证服务等。

在大多数项目中,人们不会使用所有这些服务,因此此警告表明,与其通过一次全局导入导入所有服务,不如仅导入应用程序中真正需要的服务。通过这种方式,您的构建将得到优化:生成的构建文件将仅包含您需要的 Firebase SDK 代码,而不会包含未使用的部分。

请参阅此文档项:https://firebase.google.com/docs/web/setup特别是下面的部分:

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

<小时/>

根据您的评论进行更新:

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

import messaging from 'firebase/messaging';

关于在浏览器中加载应用程序时 Firebase JS SDK 发出警告(角度 v5),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50785475/

相关文章:

authentication - Firebase 身份验证导致错误代码 "auth/network-request-failed"

javascript - 平滑滚动然后聚焦于 Angular2 应用程序

angularjs - Angular + Firebase : How to quickly load lots of data?

angularjs - 使用 AngularFire 时,光标会在键入时跳到字段末尾

parse-platform - Firebase AfterSave 功能如 Parse.com

git - 如何修复 .git 暴露的 firebase 漏洞

javascript - Firebase 存在 : onDisconnect make a transaction

javascript - 以 Angular react 形式显示条件输入框

ios - 从 Firestore 中选择一个用户

javascript - Angular5中父子元素的点击事件处理