or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-babel-preset-es2015-rollup

Babel preset for ES2015 transformation optimized for Rollup.js bundling with external helpers support

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/babel-preset-es2015-rollup@3.0.x

To install, run

npx @tessl/cli install tessl/npm-babel-preset-es2015-rollup@3.0.0

index.mddocs/

babel-preset-es2015-rollup

babel-preset-es2015-rollup is a customized Babel preset that provides ES2015+ JavaScript transformation specifically optimized for use with Rollup.js bundler. It extends the standard babel-preset-es2015 by removing CommonJS module transformation and adding external helpers support to enable efficient tree-shaking and bundle optimization.

Package Information

  • Package Name: babel-preset-es2015-rollup
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install babel-preset-es2015-rollup

Core Imports

const babelPresetEs2015Rollup = require("babel-preset-es2015-rollup");

Note: This package uses CommonJS and exports via module.exports. ES module imports may not work reliably in all environments.

Basic Usage

// With babel-core transform
const babel = require("babel-core");
const preset = require("babel-preset-es2015-rollup");

const result = babel.transform(
  "const greet = (name) => `Hello, ${name}!`;",
  { presets: [preset] }
);
console.log(result.code);
// Output: "var greet = function greet(name) { return \"Hello, \" + name + \"!\"; };"

// With rollup-plugin-babel
// rollup.config.js
import babel from "rollup-plugin-babel";

export default {
  input: "src/main.js",
  output: { file: "dist/bundle.js", format: "umd" },
  plugins: [
    babel({
      presets: [require("babel-preset-es2015-rollup")],
      exclude: "node_modules/**"
    })
  ]
};

Architecture

The preset is constructed by:

  1. Base Loading: Imports all plugins from babel-preset-es2015
  2. Module Filtering: Removes babel-plugin-transform-es2015-modules-commonjs to preserve ES modules
  3. Helper Addition: Adds babel-plugin-external-helpers for shared helper functions
  4. Plugin Export: Exports the modified plugin array as a Babel preset configuration

This approach enables:

  • ES Module Preservation: Maintains import/export statements for Rollup's tree-shaking
  • Helper Deduplication: Reduces bundle size through external helper sharing
  • ES2015+ Support: Transforms all ES2015 features except modules

Capabilities

Babel Preset Configuration

Provides a complete Babel preset configuration object optimized for Rollup.js bundling workflows.

/**
 * Default export providing Babel preset configuration
 * @returns {PresetConfiguration} Babel preset with plugins array
 */
module.exports: PresetConfiguration;

interface PresetConfiguration {
  /** Array of Babel plugins for ES2015 transformation */
  plugins: BabelPlugin[];
}

type BabelPlugin = string | [string, PluginOptions] | Function | [Function, PluginOptions];

interface PluginOptions {
  [key: string]: any;
}

Key Features:

  • ES2015 Transformation: Converts arrow functions, destructuring, classes, template literals, and other ES2015+ features
  • Module Preservation: Leaves import and export statements unchanged for Rollup processing
  • External Helpers: Uses shared Babel helper functions to reduce code duplication
  • Rollup Optimization: Specifically designed for optimal bundling with Rollup.js

Usage Examples:

// Direct usage with babel-core
const babel = require("babel-core");
const preset = require("babel-preset-es2015-rollup");

// Transform ES2015 features (excluding modules)
const code = "() => {};";
const result = babel.transform(code, { presets: [preset] });
console.log(result.code); // "(function () {});"

// Modules are preserved for Rollup
const moduleCode = 'import foo from "foo"; export default 0;';
const moduleResult = babel.transform(moduleCode, { presets: [preset] });
console.log(moduleResult.code); // 'import foo from "foo"; export default 0;'

// External helpers are used for certain operations
const helperCode = "typeof a;";
const helperResult = babel.transform(helperCode, { presets: [preset] });
console.log(helperResult.code); 
// 'typeof a === "undefined" ? "undefined" : babelHelpers.typeof(a);'

Dependencies and Compatibility

Runtime Dependencies:

  • babel-preset-es2015 (^6.3.13): Base ES2015 preset
  • babel-plugin-external-helpers (^6.18.0): External helper support
  • require-relative (^0.8.7): Relative module resolution utility

Compatibility:

  • Babel Version: Compatible with Babel 6.x
  • Node.js: Requires Node.js environment for preset configuration
  • Rollup Integration: Designed for use with rollup-plugin-babel
  • ES Module Support: Preserves ES modules for modern bundling workflows

Typical Workflow:

  1. Install alongside rollup-plugin-babel
  2. Configure in Rollup config or .babelrc
  3. Build process transforms ES2015+ syntax while preserving modules
  4. Rollup performs tree-shaking and bundling with ES module support