Ember CLI Babel Transpilation

8.3.1 · active · verified Wed Apr 22

ember-cli-babel is the official Ember CLI addon responsible for integrating Babel into Ember applications and addons. It transpiles modern JavaScript (ESNext) down to a syntax supported by target browsers, leveraging `@babel/preset-env` and respecting the `config/targets.js` file. The current stable version is 8.3.1, with releases occurring as needed to align with Babel updates, Ember CLI changes, and bug fixes. Key differentiators include its deep integration with the Ember CLI build pipeline, automatic polyfill management (though `includePolyfill` was removed in v8), and support for advanced features like static class blocks and TypeScript transpilation. It provides a robust, zero-config-by-default setup while offering extensive customization options through the `ember-cli-build.js` file for both Babel presets/plugins and `ember-cli-babel`'s internal behavior, making it indispensable for modern Ember development.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to configure `ember-cli-babel` within `ember-cli-build.js`, including setting Babel options (like `loose` mode and custom plugins) and `ember-cli-babel` specific options (like enabling TypeScript transpilation or disabling debug tooling).

/* eslint-env node */
'use strict';

const EmberApp = require('ember-cli/lib/broccoli/ember-app');

module.exports = function (defaults) {
  let app = new EmberApp(defaults, {
    // Configure Babel transpilation options
    babel: {
      // Enable "loose" mode for class properties for smaller output and compatibility.
      loose: true,
      // Exclude a specific transform if not needed or handled by other means.
      exclude: [
        'transform-regenerator'
      ],
      // Add custom Babel plugins, using require.resolve for robust path resolution.
      plugins: [
        require.resolve('@babel/plugin-proposal-decorators') // Common in Ember for decorators
      ]
    },

    // Configure ember-cli-babel specific options
    'ember-cli-babel': {
      // Disable debug tooling support for production builds to optimize size.
      disableDebugTooling: EmberApp.env() === 'production',
      // Enable TypeScript transpilation if your project uses TypeScript.
      // Note: This handles syntax transpilation, not type checking.
      enableTypeScriptTransform: true,
      // Specify additional file extensions for Babel to process.
      extensions: ['js', 'ts', 'gjs', 'gts']
    }

    // Other EmberApp configurations go here
  });

  return app.toTree();
};

view raw JSON →