Babel 中文文档
  • 印记中文
  • 文档
  • 配置
  • 试用
  • 视频
  • 博客
  • 赞助
  • 团队
  • GitHub
Edit

@babel/runtime-corejs2

@babel/runtime-corejs2 is a library that contain's Babel modular runtime helpers as well as version 2 of core-js.

Installation

npm install --save @babel/runtime-corejs2

See also: @babel/runtime.

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 A {}

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-corejs2 version.

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

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

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

Difference from @babel/runtime

This can be used instead of a polyfill for any non-instance methods. It will replace things like Promise or Symbol with the library functions in core-js.

Promise;

turns into:

var _Promise = require("@babel/runtime-corejs2/core-js/promise.js");

This transformation is also applied for Babel's helpers.

  • Installation
  • Usage
  • Why
  • Difference from @babel/runtime
Babel 中文文档
文档
学习 ES2015
社区
视频用户Stack OverflowSlack 频道Twitter
更多
博客GitHub 组织GitHub 仓库Website 仓库旧版网址 6.x旧版网址 5.x