【问题标题】:How to stop the warning: It looks like you're using the development build of the Firebase JS SDK?如何停止警告:您似乎正在使用 Firebase JS SDK 的开发版本?
【发布时间】:2018-11-22 20:24:37
【问题描述】:
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 CDN builds, these are available in the following manner
(replace <PACKAGE> with the name of a component - i.e. auth, database, etc):

https://www.gstatic.com/firebasejs/5.0.0/firebase-<PACKAGE>.js

它占用了我已经有限的控制台空间的一半 :(

注意:我在 html 中使用 firebase .. 和 script 标签。我不使用这里解释的导入语法:similar question

如何停止这个警告?

【问题讨论】:

    标签: javascript firebase


    【解决方案1】:

    为了更清楚地回答这个问题,

    你最有可能拥有的是

    <script src="https://www.gstatic.com/firebasejs/6.0.2/firebase.js"></script>
    

    因为这是 Firebase 在“将 Firebase 添加到您的网络应用”屏幕中为您提供的内容。

    但是,这样做是导入所有 Firebase 模块。我不知道为什么 Firebase 将其作为生成的脚本,但您需要做的就是将 -app 添加到源代码中,这样就可以了。

    <script src="https://www.gstatic.com/firebasejs/6.0.2/firebase-app.js"></script>
    

    然后,对于您想要使用的 Firebase 的每个后续功能,您将需要添加另一个脚本行。例如,如果您想将云消息添加到您的 Web 应用程序,它只需要。

    <script src="https://www.gstatic.com/firebasejs/6.0.2/firebase-app.js"></script>
    <script src="https://www.gstatic.com/firebasejs/6.0.2/firebase-messaging.js"></script>
    

    您可以找到更多信息,包括完整的进口清单here from Firebase.

    【讨论】:

      【解决方案2】:

      here给出的细节不是超级好理解:

      第 1 步:删除以下行,因为它是开发版本:

      <script src="https://www.gstatic.com/firebasejs/5.8.6/firebase.js"></script>
      

      第 2 步:添加以下行,(必需),生产版本:

      <script src="https://www.gstatic.com/firebasejs/5.8.6/firebase-app.js"></script>
      

      第 3 步:添加您需要的更多包/服务,例如数据库、(可选)、生产构建:

      <script src="https://www.gstatic.com/firebasejs/5.8.6/firebase-database.js"></script>
      

      这解决了问题。

      【讨论】:

      • 这个和this answer基本一样。
      • @andr%c3%a9-kool 答案中哪里有production这个词?,你的阅读和理解时间是不是太长了?为什么要为别人浪费很多时间?我不介意投反对票,我会为其他人保留答案。
      【解决方案3】:

      您的错误消息告诉您如何修复它...这部分就在这里:

      For the CDN builds, these are available in the following manner
      (replace <PACKAGE> with the name of a component - i.e. auth, database, etc):
      
      https://www.gstatic.com/firebasejs/5.0.0/firebase-<PACKAGE>.js
      

      因此,如果您使用 Firebase 身份验证,您将有一个请求 https://www.gstatic.com/firebasejs/5.0.0/firebase-auth.js ...您需要的任何其他 Firebase 部分。

      【讨论】:

      • 我从cdn复制粘贴了firebase.js源代码并将其放入我的项目中,以防止在开发过程中通过网络请求过多。与 firestore 相同.. 我尝试仅使用 ../firebase-firestore.js 但我收到一个错误,因为我需要导入大库.. 这反过来使firestore 导入毫无价值.. 并产生你看到的这个警告。它可能适用于 auth 和其他的。我明天再测试一下。
      • 他们在文档中确实有 2 个导入,这让我认为事情不清楚:firebase.google.com/docs/firestore/quickstart
      • 啊哈!是的,这是一个矛盾的文件。请查看此链接:firebase.google.com/docs/web/setup 您需要包含“app”组件。
      • 是的,现在说得通了..我要从 cdn 下载 fireabase-app.js 并将其放入我的项目中。
      • 我还必须链接到 firebase-app.js:&lt;script src="https://www.gstatic.com/firebasejs/5.4.0/firebase-app.js"&gt;&lt;/script&gt; &lt;script src="https://www.gstatic.com/firebasejs/5.4.0/firebase-database.js"&gt;&lt;/script&gt;
      猜你喜欢
      • 1970-01-01
      • 2023-03-06
      • 1970-01-01
      • 2020-09-24
      • 1970-01-01
      • 2019-01-17
      • 2021-05-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多