babel-plugin-uglify
raw JSON → 1.0.2 verified Sat Apr 25 auth: no javascript deprecated
Babel plugin that integrates UglifyJS minification directly into the Babel pipeline without needing to generate and re-parse code. v1.0.2 is the latest stable release. This plugin works on the Mozilla AST (SpiderMonkey format) used internally by Babel, avoiding repeated code generation and parsing. It is intended for Babel 5.x only, as Babel 6+ uses different AST formats. No longer actively maintained; alternatives include babel-minify (babili) or terser-based plugins. Key differentiator: direct AST-level minification preserves source maps and avoids overhead of stringifying and re-parsing code.
Common errors
error Couldn't find preset "es2015" relative to directory ↓
cause Missing Babel preset when trying to run transforms before uglify
fix
Install and configure Babel presets (e.g., babel-preset-es2015) in .babelrc or programmatic options.
error Unexpected token: name (x) ↓
cause Plugin ran before ES6 transformers, so UglifyJS encountered ES6 syntax
fix
Ensure plugin is specified with ':after' suffix (e.g., 'uglify:after') so it runs after ES6 transforms.
error require('babel').transform is not a function ↓
cause Using Babel 6+ API with babel-plugin-uglify which is only for Babel 5
fix
Use Babel 5 API (require('babel')) or switch to a Babel 6+ compatible minifier plugin.
Warnings
deprecated babel-plugin-uglify is deprecated. Babel 6+ does not use Mozilla AST, and this plugin is incompatible. Use babel-minify (babili) or plugins based on terser. ↓
fix Migrate to @babel/plugin-minify (babel-minify) or babel-plugin-terser.
breaking The plugin requires Babel 5.x. It will not work with Babel 6 or later due to AST format changes. ↓
fix Use Babel 5 or switch to a Babel 6+ compatible minifier.
gotcha The plugin must be specified with ':after' suffix (e.g., 'uglify:after') in Babel plugins list; otherwise it runs before ES6 transforms and UglifyJS will fail on ES6 syntax. ↓
fix Add ':after' suffix to plugin name in .babelrc or programmatic options.
deprecated UglifyJS itself is less actively maintained than terser. Consider using terser-based plugins for better ES6+ support and ongoing maintenance. ↓
fix Use babel-plugin-terser instead of babel-plugin-uglify.
Install
npm install babel-plugin-uglify yarn add babel-plugin-uglify pnpm add babel-plugin-uglify Imports
- plugin wrong
{"plugins": ["uglify"]}correct// In .babelrc: {"plugins": ["uglify:after"]}
Quickstart
// .babelrc example
{
"plugins": ["uglify:after"]
}
// Node API example
var babel = require('babel');
babel.transform('const x = 1;', {
plugins: ['uglify:after']
}, function(err, result) {
console.log(result.code);
});