@babel/runtime

@babel/runtime is a library that contains Babel modular runtime helpers.

Installation

  • npm
  • Yarn
  • pnpm
  1. npm install --save @babel/runtime
  1. yarn add @babel/runtime
  1. pnpm add @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):

JavaScript

  1. class Circle {}

turns into:

JavaScript

  1. function _classCallCheck(instance, Constructor) {
  2. //...
  3. }
  4. var Circle = function Circle() {
  5. _classCallCheck(this, Circle);
  6. };

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.

JavaScript

  1. var _classCallCheck = require("@babel/runtime/helpers/classCallCheck");
  2. var Circle = function Circle() {
  3. _classCallCheck(this, Circle);
  4. };

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