*不*开发库时,使用babel-runtime和babel-polyfill有什么实际区别? (例如,Web应用程序) [英] Is there any practical difference between using babel-runtime and the babel-polyfill when *not* developing a library? (e.g. web application)

查看:99
本文介绍了*不*开发库时,使用babel-runtime和babel-polyfill有什么实际区别? (例如,Web应用程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确实是标题中的全部内容.

It's all in the title, really.

在Babel文档中,描述babel运行时的页面上有以下行

In the Babel documentation, there is the following line on the page describing babel-runtime

此转换器的另一个目的是为您的代码创建一个沙盒环境.诸如Promise,Set和Map之类的内置别名是core-js的别名,因此您可以无缝使用它们,而无需全局污染 polyfill .

polyfill 就是这样,其中包含一个单独的JavaScript文件,可以补充一些内容缺少东西.

The polyfill is just that, a separate JavaScript file which is included which shims up some missing things.

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

I've tested the polyfill vs. using babel-runtime with my build tools (webpack), and my files are slightly smaller when I use babel-runtime.

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

I'm not developing a library or plugin, just a web application, and also do not care about the global scope being polluted. Knowing this, other than the slightly smaller final filesize, are there any other practical benefits or points in using the runtime over the polyfill?

推荐答案

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

If you don't care about polluting global scope, the polyfill is the better option: the runtime does not work with instance methods such as [0, 1, 2].includes(1), while the polyfill will.

两者之间的主要区别在于,polyfill会污染全局范围,并且可以使用实例方法,而运行时不会污染全局范围,也不可以使用实例方法.

The main difference between the two is that the polyfill pollutes global scope, and works with instance methods, while the runtime does not pollute global scope and does not work with instance methods.

polyfill也不允许您在代码中包含自身的两个单独版本.仅当在代码中需要/导入两个单独的polyfill时,这才是问题.

The polyfill also will not allow you to include two separate versions of itself into your code. This is only a problem if two separate polyfills are being required/imported somewhere in your code.

这篇关于*不*开发库时,使用babel-runtime和babel-polyfill有什么实际区别? (例如,Web应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆