返回介绍

@babel/runtime

发布于 2019-12-05 05:03:12 字数 1749 浏览 1343 评论 0 收藏 0

@babel/runtime is a library that contain's Babel modular runtime helpers and a version of regenerator-runtime.

Installation

npm install --save @babel/runtime

See also: @babel/runtime-corejs2.

Usage

This is meant to be used as a runtime dependency along with the Babel plugin @babel/plugin-transform-runtime. Please check out the documentation in that package for usage.

Why

Sometimes Babel may inject some code in the output that is the same and thus can be potentially re-used.

For example, with the class transform (without loose mode):

class Circle {}

turns into:

function _classCallCheck(instance, Constructor) {
  //...
}

var Circle = function Circle() {
  _classCallCheck(this, Circle);
};

this means every file that contains a class would have the _classCallCheck function repeated each time.

With @babel/plugin-transform-runtime, it would replace the reference to the function to the @babel/runtime version.

var _classCallCheck = require("@babel/runtime/helpers/classCallCheck");

var Circle = function Circle() {
  _classCallCheck(this, Circle);
};

@babel/runtime is just the package that contains the implementations of the functions in a modular way.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文