如何在 Vanilla JS 中使用 Firebase Polyfill
How to Use Firebase Polyfills in Vanilla JS
我目前正在构建一个普通网页,该网页使用 Google Firebase 来处理这两个 Authentication and data storage, using the Firebase Realtime Database。这就是我在 HTML 文件底部包含 Firebase 的方式:
<script src="https://www.gstatic.com/firebasejs/6.4.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/6.4.1/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/6.4.1/firebase-database.js"></script>
这在大多数浏览器中都可以正常工作。但是,在 Internet Explorer 中,它会抛出各种关于不具备某些 es6 函数的错误,最常见的是 Array.findIndex
和 Object.values
.
将 Firebase supported environments page says that polyfills are required -- fair enough. However, I'm unclear how to include the recommended "ES Stable" 放入普通 html/js 页面,因为它们的所有示例都涉及捆绑器或框架。
我正在寻找有关如何将此内容或任何解决问题的 polyfill 包含到常规 HTML/JS 页面中的示例或说明。
查看 core-js
installation section 后,他们似乎确实提供了您可以附加的 CDN。确切的文字是这样的:
Already bundled version of core-js on CDN (minified version).
你可以试试下面只包含es6特性的polyfill。我在使用 firebase 时遇到了同样的问题,并通过以下 polyfill 解决了。
只需将以下脚本加载到带有 firebase(所有版本)的纯 JavaScript 项目即可。
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=es6"></script>
You can find the direct CDN (minified version) link here.
我目前正在构建一个普通网页,该网页使用 Google Firebase 来处理这两个 Authentication and data storage, using the Firebase Realtime Database。这就是我在 HTML 文件底部包含 Firebase 的方式:
<script src="https://www.gstatic.com/firebasejs/6.4.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/6.4.1/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/6.4.1/firebase-database.js"></script>
这在大多数浏览器中都可以正常工作。但是,在 Internet Explorer 中,它会抛出各种关于不具备某些 es6 函数的错误,最常见的是 Array.findIndex
和 Object.values
.
将 Firebase supported environments page says that polyfills are required -- fair enough. However, I'm unclear how to include the recommended "ES Stable" 放入普通 html/js 页面,因为它们的所有示例都涉及捆绑器或框架。
我正在寻找有关如何将此内容或任何解决问题的 polyfill 包含到常规 HTML/JS 页面中的示例或说明。
查看 core-js
installation section 后,他们似乎确实提供了您可以附加的 CDN。确切的文字是这样的:
Already bundled version of core-js on CDN (minified version).
你可以试试下面只包含es6特性的polyfill。我在使用 firebase 时遇到了同样的问题,并通过以下 polyfill 解决了。
只需将以下脚本加载到带有 firebase(所有版本)的纯 JavaScript 项目即可。
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=es6"></script>
You can find the direct CDN (minified version) link here.