Babel
  • Docs
  • Setup
  • Try it out
  • Videos
  • Blog
  • Donate
  • Team
  • GitHub

›Tooling

Guides

  • What is Babel?
  • Usage Guide
  • Configure Babel
  • Learn ES2015
  • Upgrade to Babel 7
  • Upgrade to Babel 7 (API)

General

  • Editors
  • Plugins
  • Presets
  • Caveats
  • FAQ
  • Roadmap

Usage

  • Options
  • Config Files
  • cli
  • polyfill
  • transform-runtime
  • register

Presets

  • env
  • flow
  • react
  • typescript

Tooling

  • parser
  • core
  • generator
  • code-frame
  • helpers
  • runtime
  • template
  • traverse
  • types
Edit

@babel/runtime

@babel/runtime is a library that contains 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 across files, 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.

← helperstemplate →
  • Installation
  • Usage
  • Why
Babel
Docs
Learn ES2015
Community
VideosUser ShowcaseStack OverflowSlack ChannelTwitter
More
BlogGitHub OrgGitHub RepoWebsite RepoOld 6.x SiteOld 5.x Site