7

当应用程序在浏览器中加载时,它会给出以下警告。所以无法为 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"

请指导我哪里出错了。

4

3 回答 3

3

你没有分享你的 Angular 组件代码,所以我不能给你具体的代码。但是,我想,您像这样直接包含 Firebase,然后它会显示以下警告。

import * as firebase from 'firebase';     // It will throw warning    
import * as firebase from 'firebase/app'; // It will not throw any warning

然后根据您的需要包括特定的包。

import 'firebase/firestore';
import 'firebase/database';
import 'firebase/auth';
于 2020-05-04T09:31:05.393 回答
3

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

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

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

请参阅此文档项:https ://firebase.google.com/docs/web/setup ,尤其是说明以下内容的部分:

如果您使用的是 Browserify 或 webpack 之类的打包工具,则只需 require() 您使用的组件即可。


根据您的评论更新:

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

import messaging from 'firebase/messaging';
于 2018-06-10T16:42:17.070 回答
0

我添加以下代码,它适用于我

要求(“火力基地/消息传递”);

于 2018-06-11T06:50:42.873 回答