rollup-plugin-babel
raw JSON → 3.0.2 verified Fri May 01 auth: no javascript deprecated
Rollup plugin for seamless integration with Babel. Version 3.0.2 is the latest stable release. It allows transpiling ES6/7 code with Babel while preserving Rollup's tree-shaking and module resolution, avoiding intermediate files and sourcemap issues. Unlike running Babel before Rollup, this plugin handles transpilation per-file, preventing Babel helper duplication. Requires babel-core 6 or 7 as a peer dependency. Key differentiator: integrates directly into Rollup's plugin system, supporting .babelrc configuration and options like include/exclude patterns. Deprecated in favor of @rollup/plugin-babel as of Rollup 1.0.
Common errors
error Error: Requires Babel "7", but was loaded with "6.26.3" ↓
cause Mismatch between required babel-core version and installed version.
fix
Install compatible babel-core: npm install babel-core@^7.0.0-bridge
error Module parse failed: Unexpected token on import statement ↓
cause Babel did not transpile the file (e.g., included in node_modules) or modules: false not set.
fix
Add '/node_modules/' to exclude or configure Babel correctly: set modules: false in presets.
error Error: Plugin 0 specified in "base" provided an invalid property of type "function" ↓
cause Using a non-array plugin format in .babelrc.
fix
Ensure Babel plugins are in array format: ["plugin-name", options] or just "plugin-name".
Warnings
deprecated rollup-plugin-babel is deprecated; use @rollup/plugin-babel instead. ↓
fix Replace with @rollup/plugin-babel: npm install @rollup/plugin-babel --save-dev and update import to require('@rollup/plugin-babel')
breaking Version 2 drops support for Babel 5. Use rollup-plugin-babel@1 if still on Babel 5. ↓
fix Downgrade to version 1: npm install rollup-plugin-babel@1 --save-dev or upgrade to Babel 6+.
breaking Requires babel-core 6 or 7 as peer dependency. Installing without matching Babel version will cause runtime errors. ↓
fix Ensure babel-core (not @babel/core) is installed: npm install babel-core@^7.0.0 --save-dev
gotcha Babel presets that include module transformation (e.g., es2015 with modules) break Rollup. Must set modules: false. ↓
fix In .babelrc or plugin options: set modules: false in preset config, e.g., ["@babel/preset-env", { "modules": false }]
gotcha Using external-helpers plugin is recommended to avoid Babel helper duplication in the bundle. ↓
fix Add @babel/plugin-external-helpers to Babel plugins and set externalHelpers: true in rollup-plugin-babel options.
Install
npm install maptalks-rollup-plugin-babel yarn add maptalks-rollup-plugin-babel pnpm add maptalks-rollup-plugin-babel Imports
- default wrong
import { babel } from 'rollup-plugin-babel'correctimport babel from 'rollup-plugin-babel' - default wrong
const { babel } = require('rollup-plugin-babel')correctconst babel = require('rollup-plugin-babel') - default wrong
import babel from 'rollup-plugin-babel/default'correctimport babel from 'rollup-plugin-babel'
Quickstart
import { rollup } from 'rollup';
import babel from 'rollup-plugin-babel';
rollup({
input: 'src/main.js',
plugins: [
babel({
exclude: 'node_modules/**',
babelrc: false,
presets: [['@babel/preset-env', { modules: false }]],
plugins: ['@babel/plugin-external-helpers']
})
]
}).then(bundle => {
bundle.write({ file: 'dist/bundle.js', format: 'cjs' });
}).catch(err => console.error(err));