A Rollup plugin that compiles ES2015+ code with the Bublé compiler for fast transpilation to ES5
npx @tessl/cli install tessl/npm-rollup--plugin-buble@1.0.0@rollup/plugin-buble is a Rollup plugin that integrates the Bublé compiler to transpile ES2015+ JavaScript code to ES5-compatible code. It provides a simple and lightweight alternative to Babel for basic ES2015+ transformations with fast compilation and minimal configuration overhead.
npm install @rollup/plugin-buble --save-devimport buble from '@rollup/plugin-buble';For CommonJS:
const buble = require('@rollup/plugin-buble');import buble from '@rollup/plugin-buble';
export default {
input: 'src/index.js',
output: {
dir: 'output',
format: 'cjs'
},
plugins: [buble()]
};Creates a Rollup plugin instance that transforms ES2015+ code using the Bublé compiler.
/**
* Convert ES2015+ code with Bublé compiler
* @param options - Configuration options for the plugin
* @returns Rollup plugin instance
*/
function buble(options?: RollupBubleOptions): Plugin;Usage Examples:
// Basic usage - no configuration needed
export default {
plugins: [buble()]
};
// With transform options
export default {
plugins: [buble({
transforms: {
forOf: false,
dangerousForOf: true,
arrow: true
}
})]
};
// With file filtering
export default {
plugins: [buble({
include: 'src/**/*.js',
exclude: 'node_modules/**',
transforms: { modules: false }
})]
};Controls which files are processed by the plugin using picomatch patterns.
interface RollupBubleOptions {
/**
* A picomatch pattern, or array of patterns, of files that should be
* processed by this plugin (if omitted, all files are included by default)
*/
include?: FilterPattern;
/**
* Files that should be excluded, if `include` is otherwise too permissive.
*/
exclude?: FilterPattern;
}Examples:
// Include only specific files
buble({
include: ['src/**/*.js', 'lib/**/*.js']
})
// Exclude node_modules
buble({
exclude: 'node_modules/**'
})
// Complex patterns
buble({
include: 'src/**/*.{js,jsx}',
exclude: ['**/*.test.js', '**/fixtures/**']
})Configures Bublé compiler transformation options. All standard Bublé transform options are supported.
interface RollupBubleOptions extends TransformOptions {
/**
* Bublé transformation options - controls which ES2015+ features to transform
* The 'modules' option is automatically set to false for Rollup compatibility
*/
transforms?: {
[feature: string]: boolean;
};
/**
* Additional Bublé compiler options
*/
objectAssign?: boolean | string;
target?: { [key: string]: any };
}Common Transform Options:
buble({
transforms: {
// Transform arrow functions (default: true)
arrow: true,
// Transform classes (default: true)
classes: true,
// Transform for-of loops (default: true)
forOf: true,
// Use dangerous for-of transform (faster but less safe)
dangerousForOf: false,
// Transform destructuring (default: true)
destructuring: true,
// Transform template literals (default: true)
templateString: true,
// Transform async/await (default: false - requires regenerator)
asyncAwait: false,
// Transform object spread (default: true)
spreadRest: true
},
// Object.assign polyfill handling
objectAssign: 'Object.assign', // or true for polyfill
// Browser targets (affects which transforms are applied)
target: {
chrome: 58,
firefox: 55,
safari: 10,
edge: 15
}
})type FilterPattern = string | RegExp | Array<string | RegExp>;
interface TransformOptions {
transforms?: { [key: string]: boolean };
objectAssign?: boolean | string;
target?: { [key: string]: any };
source?: string;
file?: string;
includeContent?: boolean;
}
interface RollupBubleOptions extends TransformOptions {
include?: FilterPattern;
exclude?: FilterPattern;
}
interface Plugin {
name: string;
transform?: (code: string, id: string) => any;
}The plugin enhances Bublé compilation errors with additional context:
e.plugin: Set to 'buble' to identify the sourcee.loc.file: The file path where the error occurrede.frame: Code snippet showing the error locationError Example:
// If Bublé encounters invalid syntax:
// Error: Unexpected token (line 5, column 12)
// Plugin: buble
// File: /project/src/component.js
// Frame: [code snippet around error]