babel-preset-minify
raw JSON → 0.5.2 verified Sat Apr 25 auth: no javascript maintenance
Babel preset that bundles all babel-minify plugins for minification. Current stable version is 0.5.2 (last release Sep 2018). This project is part of the babel/minify monorepo, which is now in maintenance mode with no active development. The preset provides a convenient way to apply minification transforms like dead code elimination, constant folding, mangle names, and more via a single preset. Unlike terser or uglify, it operates as a Babel transform, allowing integration with Babel workflows and AST-level optimizations. It supports options to enable/disable individual plugins and has known missing dependency issues.
Common errors
error Error: Cannot find module 'babel-preset-minify' ↓
cause Forgot to install the package as devDependency.
fix
Run: npm install babel-preset-minify --save-dev
error TypeError: Cannot read property 'minify' of undefined ↓
cause Misconfigured Babel presets (e.g., using 'babel-preset-minify' instead of 'minify' or array syntax wrong).
fix
Use "presets": ["minify"] or "presets": [["minify", { options }]]
error ERROR: The 'blacklist' option has been removed. Use 'exclude'. ↓
cause Using old 'blacklist' option with babel-preset-minify >= 0.3.0.
fix
Replace 'blacklist' with 'exclude' in mangle options.
error Module not found: Can't resolve 'babel-preset-minify' in ... ↓
cause Webpack or other bundler trying to import the preset as a module directly.
fix
Do not import babel-preset-minify directly in code; use it only in Babel config.
Warnings
deprecated babel-minify project is no longer actively maintained. Consider using terser or a more modern minifier. ↓
fix Migrate to terser (via @babel/plugin-minify? but prefer standalone) or use babel-plugin-uglify or similar.
breaking Missing dependencies in version 0.5.1 causing runtime errors ↓
fix Upgrade to 0.5.2 or pin to 0.5.0. Also, ensure all peer dependencies are installed (babel-core 6.x).
breaking Renamed from Babili to babel-minify in version 0.2.0. Old import paths and configuration break. ↓
fix Update presets from 'babili' to 'minify' and update package names accordingly.
deprecated The 'blacklist' option for mangle plugin renamed to 'exclude' in version 0.3.0. ↓
fix Use 'exclude' instead of 'blacklist' in mangle options.
gotcha Does not support ES modules. Only CommonJS via require(). Using import will fail. ↓
fix Use require() for Node.js. For bundlers, ensure Babel is configured properly.
Install
npm install babel-preset-minify yarn add babel-preset-minify pnpm add babel-preset-minify Imports
- default wrong
import preset from 'babel-preset-minify'correctmodule.exports = require('babel-preset-minify') - preset declaration wrong
"presets": ["babel-preset-minify"]correct"presets": ["minify"] in .babelrc or babel.config.js - Node API usage wrong
const minify = require('babel-preset-minify'); minify(code)correctconst babel = require('@babel/core'); babel.transform(code, { presets: ['minify'] })
Quickstart
// Install: npm install babel-preset-minify --save-dev
// Example .babelrc
{
"presets": [
["minify", {
"mangle": {
"exclude": ["MyCustomError"]
},
"removeConsole": true,
"keepFnName": false
}]
]
}
// Node API usage
const babel = require('@babel/core');
const fs = require('fs');
const code = fs.readFileSync('./input.js', 'utf8');
const output = babel.transformSync(code, {
presets: ['minify']
});
fs.writeFileSync('./output.min.js', output.code);