在*不*开发库时使用 babel-runtime 和 babel-polyfill 之间有什么实际区别吗? (例如网络应用程序)

Is there any practical difference between using babel-runtime and the babel-polyfill when *not* developing a library? (e.g. web application)

标题里都有,真的。

在 Babel 文档中,page describing babel-runtime

上有以下行

Another purpose of this transformer is to create a sandboxed environment for your code. Built-ins such as Promise, Set and Map are aliased to core-js so you can use them seamlessly without having to require a globally polluting polyfill.

polyfill 就是一个单独的 JavaScript 文件,它包含了一些缺失的东西。

我已经通过我的构建工具 (webpack) 测试了 polyfill 与使用 babel-runtime 的对比,并且当我使用 [=27= 时我的文件 略微 ].

我不是在开发库或插件,只是一个网络应用程序,也不关心全局范围被污染。知道这一点,除了最终文件大小略小之外,在 polyfill 上使用运行时还有其他实际好处或要点吗?

如果您不关心污染全局范围,polyfill 是更好的选择:运行时不适用于 [0, 1, 2].includes(1) 等实例方法,而 polyfill 会。

两者的主要区别在于,polyfill 会污染全局作用域,并且使用实例方法,而运行时不会污染全局作用域,并且不会使用实例方法。

polyfill 也不允许您将其自身的两个单独版本包含到您的代码中。如果代码中的某处 required/imported 有两个单独的 polyfill,这只是一个问题。