babel-plugin-compact-reexports

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

A Babel plugin that optimizes ES module re-exports in AMD by replacing verbose definitions with concise alias calls. Version 1.1.0 is the latest stable release. The plugin targets Ember applications using loader.js but can work with any AMD loader supporting alias API. Differentiator: drastically reduces boilerplate for re-export-only modules, saving bytes over the wire in production builds.

error Error: .plugins[0][0] must be a string, object, function
cause Using an incorrect plugin name or not installing the plugin
fix
Run 'npm install babel-plugin-compact-reexports --save-dev' and ensure Babel config has 'compact-reexports' in plugins array.
error Cannot find module 'babel-plugin-compact-reexports'
cause Plugin not installed in local node_modules
fix
Run 'npm install babel-plugin-compact-reexports --save-dev'.
gotcha Plugin only works with AMD module format. If not using AMD (e.g., CommonJS or ESM output), the plugin does nothing.
fix Ensure Babel is configured to output AMD modules, e.g., using @babel/plugin-transform-modules-amd.
gotcha Alias relies on loader.js API. Custom AMD loaders without alias support will ignore the alias call, potentially causing module resolution failures.
fix Verify your AMD loader supports similar alias functionality, or avoid using this plugin.
gotcha Only handles re-exports of the form 'export { default } from ...' or 'export * from ...'. Complex re-exports (renamed, multiple) are not optimized.
fix Simplify re-exports to plain default or star exports to benefit from compaction.
npm install babel-plugin-compact-reexports
yarn add babel-plugin-compact-reexports
pnpm add babel-plugin-compact-reexports

Shows Babel configuration and the optimization from verbose AMD define to compact alias.

// .babelrc.js
module.exports = {
  plugins: ['compact-reexports']
};

// Input: my-module.js
export { default } from 'their-module';

// Compiled output:
define.alias('their-module', 'my-module');