babel-minify (formerly Babili)
raw JSON → 0.5.2 verified Sat Apr 25 auth: no javascript maintenance
An ES6+ aware JavaScript minifier based on the Babel toolchain. Current stable version is 0.5.2, released in 2018. Development has been stalled since then; it is effectively in maintenance mode. Unlike traditional minifiers (UglifyJS, Terser), babel-minify operates on an AST that can understand modern ES6+ syntax, allowing it to minify code without needing to down-compile first. It works as a standalone CLI tool or as a Babel preset. Note: it is deprecated in favor of Terser for most use cases because Babel itself stopped maintaining it.
Common errors
error Error: Cannot find module 'babel-plugin-minify-dead-code-elimination' ↓
cause Missing dependency in babel-minify 0.5.0/0.5.1; the package didn't declare all dependencies.
fix
Upgrade to babel-minify@0.5.2 or install missing plugins manually.
error TypeError: minify is not a function ↓
cause Using ES module import (import minify from 'babel-minify') which returns an object with default property, not the function directly.
fix
Use
const minify = require('babel-minify'); or in ESM: import minify from 'babel-minify'; with proper bundler handling. error Error: Preset babel-preset-minify not found. ↓
cause babel-preset-minify is a peer dependency not automatically installed; missing or wrong version.
fix
Install babel-preset-minify explicitly: npm install babel-preset-minify --save-dev
error ENOENT: no such file or directory, open 'input.js' ↓
cause CLI command invoked without specifying input file correctly or file does not exist.
fix
Ensure input file path is correct and use --out-file for output.
Warnings
deprecated babel-minify is no longer actively maintained; Babel recommends using Terser for minification. ↓
fix Switch to terser for active development and bug fixes.
breaking Breaking change in 0.4.0: significant API overhaul; compatibility with older babel versions dropped. ↓
fix Update code to use new API; refer to changelog.
breaking Renamed from Babili to babel-minify in 0.2.0; package name changed. ↓
fix Replace 'babili' requires with 'babel-minify'.
gotcha Does not support ES module imports; must use require() or configure bundler accordingly. ↓
fix Use CommonJS require; if using ESM, consider dynamic import or use Terser.
gotcha Missing dependencies in versions 0.5.0 and 0.5.1 causing installation failures. ↓
fix Upgrade to 0.5.2 or manually install missing peer dependencies like @babel/core.
Install
npm install babel-minify yarn add babel-minify pnpm add babel-minify Imports
- minify wrong
import minify from 'babel-minify';correctconst minify = require('babel-minify'); - minify wrong
const minify = require('babel-minify').minify;correctconst minify = require('babel-minify').default || require('babel-minify'); - transform wrong
const { transform } = require('babel-minify');correctconst { transform } = require('@babel/core');
Quickstart
const minify = require('babel-minify');
const inputCode = `function hello(name) { console.log('Hello, ' + name); }`;
const options = {
mangle: { keepClassName: true },
deadcode: { keepFnArgs: false }
};
try {
const { code, map } = minify(inputCode, options);
console.log('Minified code:', code);
} catch (err) {
console.error('Minification failed:', err);
}