使用 babel-polyfill 为什么要使用 babel-plugin-transform-runtime

发布于 2022-09-06 08:55:01 字数 241 浏览 16 评论 0

想在 node 中使用 Generator, 添加添加 babel-polyfill 后发现还是无法使用,加上 babel-plugin-transform-runtime 后没有问题了。

我想知道原因是什么,我认为 babel-plugin-transform-runtime 应该和 babel-runtime 配合

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

游魂 2022-09-13 08:55:01

https://babeljs.io/docs/plugi...

Another purpose of this transformer is to create a sandboxed environment for your code. If you use babel-polyfill and the built-ins it provides such as Promise, Set and Map, those will pollute the global scope. While this might be ok for an app or a command line tool, it becomes a problem if your code is a library which you intend to publish for others to use or if you can’t exactly control the environment in which your code will run.

就是说它会为 babel-polyfill 提供的功能创建沙盒环境。

示例中还有个配置,看样子是可以避免创建 polyfill 沙盒的:

{
  "plugins": [
    ["transform-runtime", {
      "helpers": false,
      "polyfill": false,
      "regenerator": true,
      "moduleName": "babel-runtime"
    }]
  ]
}

至于为什么添加 babel-polyfill 后无法使用……你到底是怎么添加的呢?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文