or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

configuration-options.mdcore-addon-interface.mdindex.mdplugin-generation.mdutility-functions.md
tile.json

plugin-generation.mddocs/

Plugin Generation

The plugin generation API allows external consumers to generate Ember-specific Babel plugins for use in custom babel.config.js configurations, enabling advanced build customization outside of the standard Ember CLI build pipeline.

Capabilities

buildEmberPlugins

The main export function that generates a complete array of Ember-specific Babel plugins.

/**
 * Generates complete set of Ember-specific Babel plugins
 * @param appRoot - Root directory path of the project (usually __dirname)
 * @param config - Optional configuration object to customize plugin behavior
 * @returns Array of Babel plugins required for Ember applications
 */
function buildEmberPlugins(appRoot: string, config?: PluginConfig): BabelPlugin[];

interface PluginConfig {
  /** Disable module resolution plugins */
  disableModuleResolution?: boolean;
  /** Force enable EmberData packages polyfill */
  emberDataVersionRequiresPackagesPolyfill?: boolean;
  /** Ignore jQuery in modules API polyfill */
  shouldIgnoreJQuery?: boolean;
  /** Ignore @ember/string in modules API polyfill */
  shouldIgnoreEmberString?: boolean;
  /** Disable decorator and class property plugins */
  shouldIgnoreDecoratorAndClassPlugins?: boolean;
  /** Disable Ember modules API polyfill */
  disableEmberModulesAPIPolyfill?: boolean;
}

type BabelPlugin = string | [string, any] | [any, any];

Usage Examples:

// babel.config.js - Basic usage
const { buildEmberPlugins } = require('ember-cli-babel');

module.exports = function(api) {
  api.cache(true);

  return {
    presets: [
      [require.resolve('@babel/preset-env'), {
        targets: require('./config/targets')
      }]
    ],
    plugins: [
      // Include all Ember-specific plugins
      ...buildEmberPlugins(__dirname),
      // Add custom plugins
      require.resolve('babel-plugin-transform-object-rest-spread')
    ]
  };
};

// babel.config.js - With custom configuration
const { buildEmberPlugins } = require('ember-cli-babel');

module.exports = function(api) {
  api.cache(true);

  return {
    presets: [
      [require.resolve('@babel/preset-env'), {
        targets: require('./config/targets')
      }]
    ],
    plugins: [
      // External helpers for smaller bundles
      [require.resolve('@babel/plugin-transform-runtime'), {
        version: require('@babel/runtime/package').version,
        regenerator: false,
        useESModules: true
      }],
      // Ember plugins with custom config
      ...buildEmberPlugins(__dirname, {
        disableModuleResolution: false,
        shouldIgnoreJQuery: true,
        disableEmberModulesAPIPolyfill: false
      })
    ]
  };
};

Individual Plugin Generators

Individual functions for generating specific plugin categories, useful for fine-grained control.

getDebugMacroPlugins

/**
 * Generates debug macro plugins for @ember/debug stripping
 * @param appRoot - Root directory path of the project
 * @returns Array of debug macro Babel plugins
 */
function getDebugMacroPlugins(appRoot: string): BabelPlugin[];

Generates plugins for:

  • @ember/debug statement stripping in production
  • @ember/application/deprecations handling
  • @glimmer/env DEBUG flag processing

Usage Example:

const { getDebugMacroPlugins } = require('ember-cli-babel');

// Use only debug macro plugins
const plugins = getDebugMacroPlugins(__dirname);

getEmberModulesAPIPolyfill

/**
 * Generates Ember modules API polyfill plugin
 * @param appRoot - Root directory path of the project
 * @param config - Configuration object
 * @returns Array containing modules API polyfill plugin or empty array
 */
function getEmberModulesAPIPolyfill(appRoot: string, config: object): BabelPlugin[] | [];

Provides polyfill for legacy Ember global API access patterns when using modern Ember versions.

Usage Example:

const { getEmberModulesAPIPolyfill } = require('ember-cli-babel');

const plugins = getEmberModulesAPIPolyfill(__dirname, {
  disableEmberModulesAPIPolyfill: false
});

getEmberDataPackagesPolyfill

/**
 * Generates EmberData packages polyfill plugin
 * @param appRoot - Root directory path of the project
 * @param config - Configuration object
 * @returns Array containing EmberData polyfill plugin or empty array
 */
function getEmberDataPackagesPolyfill(appRoot: string, config: object): BabelPlugin[] | [];

Provides polyfill for EmberData package structure changes in older versions.

Usage Example:

const { getEmberDataPackagesPolyfill } = require('ember-cli-babel');

const plugins = getEmberDataPackagesPolyfill(__dirname, {
  emberDataVersionRequiresPackagesPolyfill: true
});

getModuleResolutionPlugins

/**
 * Generates module resolution plugins for AMD compilation
 * @param config - Configuration object
 * @returns Array of module resolution plugins or empty array
 */
function getModuleResolutionPlugins(config: object): BabelPlugin[] | [];

Provides plugins for:

  • Module path resolution
  • AMD module compilation
  • Relative module path handling

Usage Example:

const { getModuleResolutionPlugins } = require('ember-cli-babel');

const plugins = getModuleResolutionPlugins({
  disableModuleResolution: false
});

getProposalDecoratorsAndClassPlugins

/**
 * Generates decorator and class property plugins
 * @param config - Configuration object
 * @returns Array of decorator and class plugins or empty array
 */
function getProposalDecoratorsAndClassPlugins(config: object): BabelPlugin[] | [];

Provides plugins for:

  • Legacy decorators support
  • Class properties
  • Class static blocks
  • Private methods and properties

Usage Example:

const { getProposalDecoratorsAndClassPlugins } = require('ember-cli-babel');

const plugins = getProposalDecoratorsAndClassPlugins({
  shouldIgnoreDecoratorAndClassPlugins: false
});

Plugin Categories

The generated plugins are organized into functional categories:

Debug Tooling Plugins

  • babel-plugin-debug-macros: Strips debug statements in production
  • Environment-specific configuration: Handles DEBUG flags and CI detection

Polyfill Plugins

  • babel-plugin-ember-modules-api-polyfill: Legacy API compatibility
  • babel-plugin-ember-data-packages-polyfill: EmberData package structure compatibility

Module Compilation Plugins

  • babel-plugin-module-resolver: Path resolution for AMD modules
  • @babel/plugin-transform-modules-amd: ES6 to AMD module compilation

Class Feature Plugins

  • @babel/plugin-transform-class-static-block: Static block syntax support
  • @babel/plugin-proposal-decorators: Legacy decorator support
  • @babel/plugin-proposal-class-properties: Class property syntax
  • @babel/plugin-proposal-private-methods: Private method syntax
  • @babel/plugin-proposal-private-property-in-object: Private property syntax

Configuration Options

disableModuleResolution

Disables AMD module compilation and path resolution plugins.

buildEmberPlugins(__dirname, {
  disableModuleResolution: true
});

emberDataVersionRequiresPackagesPolyfill

Forces inclusion of EmberData packages polyfill regardless of version detection.

buildEmberPlugins(__dirname, {
  emberDataVersionRequiresPackagesPolyfill: true
});

shouldIgnoreJQuery

Excludes jQuery from modules API polyfill ignore list.

buildEmberPlugins(__dirname, {
  shouldIgnoreJQuery: true
});

shouldIgnoreEmberString

Excludes @ember/string from modules API polyfill ignore list.

buildEmberPlugins(__dirname, {
  shouldIgnoreEmberString: true
});

shouldIgnoreDecoratorAndClassPlugins

Disables all decorator and class feature plugins.

buildEmberPlugins(__dirname, {
  shouldIgnoreDecoratorAndClassPlugins: true
});

disableEmberModulesAPIPolyfill

Disables the Ember modules API polyfill entirely.

buildEmberPlugins(__dirname, {
  disableEmberModulesAPIPolyfill: true
});

Version Detection

The plugin generation system automatically detects package versions to determine which polyfills and transforms are necessary:

  • Ember version detection: Determines if modules API polyfill is needed
  • EmberData version detection: Determines if packages polyfill is needed
  • @ember/jquery version detection: Configures jQuery polyfill behavior
  • @ember/string detection: Configures string utility polyfill behavior

This ensures optimal plugin configuration for your specific dependency versions.

Error Handling

Plugin generation is designed to be robust:

  • Missing dependencies: Gracefully handles missing optional dependencies
  • Version parsing errors: Falls back to safe defaults when version detection fails
  • Invalid configuration: Ignores invalid configuration options and uses defaults
  • Plugin resolution failures: Continues processing even if individual plugins fail to resolve