broccoli-babel-transpiler

raw JSON →
8.0.2 verified Sat Apr 25 auth: no javascript

A Broccoli plugin for transpiling ES6+ to readable ES5 using Babel, with caching and parallelization. Current stable version 8.0.2 supports Node 16+ and 18+ and requires @babel/core >=7.17.9 as a peer dependency. Key differentiators include persistent caching across rebuilds (via cacheKey/cacheKeyPlugin methods) and async plugin support since v8.0.1. Notable breaking changes in v8 include dropping Node 14 and moving @babel/core to peer deps. Commonly used in Ember.js and other Broccoli-based build pipelines.

error Cannot find module '@babel/core'
cause @babel/core is not installed because it moved to peerDependencies in v8.
fix
npm install --save-dev @babel/core
error TypeError: babel is not a function
cause Using ES module import (import babel from '...') on a CJS package.
fix
Use require('broccoli-babel-transpiler') instead.
breaking Since v8.0.0, @babel/core is no longer bundled; it must be installed as a peer dependency.
fix Install @babel/core explicitly in your project: npm install --save-dev @babel/core
breaking Node 14 support dropped in v8.0.0.
fix Upgrade to Node 16 or 18.
gotcha Empty options will not transpile anything; you must specify presets or plugins explicitly.
fix Provide a presets or plugins array in the Babel options.
gotcha Plugin caching requires implementing cacheKey() method on the plugin; otherwise, the plugin's effect is not cached and may cause unnecessary rebuilds.
fix Define a cacheKey() method that returns a string uniquely representing plugin configuration.
npm install broccoli-babel-transpiler
yarn add broccoli-babel-transpiler
pnpm add broccoli-babel-transpiler

Shows how to use broccoli-babel-transpiler with a Brocfile-like setup: funnel source files, transpile via babel with preset-env targeting modern browsers, then build with Broccoli.

const babel = require('broccoli-babel-transpiler');
const broccoli = require('broccoli');
const funnel = require('broccoli-funnel');

// Create a tree of JavaScript files
const appTree = funnel('src', { include: ['**/*.js'] });

// Transpile with babel
const transpiled = babel(appTree, {
  presets: [
    ['@babel/preset-env', {
      targets: { browsers: ['last 2 versions'] }
    }]
  ]
});

// Build the output
const builder = new broccoli.Builder(transpiled);
builder.build().then(() => {
  console.log('Build complete!');
}).catch(err => console.error(err));