UglifyJS Webpack Plugin
raw JSON → 2.2.0 verified Sat Apr 25 auth: no javascript maintenance
UglifyJS Webpack Plugin uses UglifyJS (v2) to minify JavaScript bundles generated by webpack. The latest stable version is 2.2.0, released July 2019, supporting webpack 4+ and Node 6.9+. It offers caching, parallelization, source maps, and advanced options like chunk filtering. However, it is now largely superseded by terser-webpack-plugin, which supports ES6+ and is the recommended minimizer for webpack 4+. This plugin switched back from uglify-es to uglify-js in v2.0.0, meaning it does not handle modern JavaScript (ES6+) out of the box. It is in maintenance mode with no active development.
Common errors
error Error: Plugin could not be used because optimization.minimizer is not an array. ↓
cause Plugin is placed directly in plugins array instead of optimization.minimizer.
fix
Move the plugin instance to optimization: { minimizer: [new UglifyJsPlugin()] }.
error TypeError: Cannot read property 'call' of undefined ↓
cause Incorrect import or missing 'new' keyword when instantiating plugin.
fix
Use: const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); new UglifyJsPlugin();
error Error: uglify-js@3.x is not compatible with this plugin. ↓
cause Package depends on uglify-js v2, but uglify-js v3 is installed.
fix
Ensure uglify-js version 2.x is installed (npm install uglify-js@2).
error UglifyJsPlugin: parallel option not supported in single-threaded mode ↓
cause Setting parallel: true on platforms with a single CPU or where worker farm fails.
fix
Set parallel: false or ensure worker-farm is properly installed.
Warnings
breaking uglify-es has been abandoned; uglifyjs-webpack-plugin switched back to uglify-js in v2.0.0. ↓
fix For ES6+ support, migrate to terser-webpack-plugin.
deprecated This plugin is in maintenance mode; no new features are being added. ↓
fix Use terser-webpack-plugin for active development and ES6+ minification.
gotcha Parallelization may fail on Windows Subsystem for Linux (WSL); disable with parallel: false. ↓
fix Set parallel: false in plugin options.
gotcha Default cache directory is node_modules/.cache/uglifyjs-webpack-plugin; may cause issues in CI environments. ↓
fix Set cache to a custom path or disable cache in CI.
gotcha Plugin options must be placed under webpack optimization.minimizer, not under plugins. ↓
fix Use optimization: { minimizer: [new UglifyJsPlugin()] } in webpack config.
breaking Default extract comment condition is case insensitive, may produce different results than v1. ↓
fix Explicitly set extractComments option to control comment extraction.
Install
npm install uglifyjs-webpack-plugin yarn add uglifyjs-webpack-plugin pnpm add uglifyjs-webpack-plugin Imports
- UglifyJsPlugin wrong
import UglifyJsPlugin from 'uglifyjs-webpack-plugin';correctconst UglifyJsPlugin = require('uglifyjs-webpack-plugin'); - UglifyJsPlugin wrong
import { UglifyJsPlugin } from 'uglifyjs-webpack-plugin';correctconst UglifyJsPlugin = require('uglifyjs-webpack-plugin'); - default
import UglifyJsPlugin from 'uglifyjs-webpack-plugin';
Quickstart
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
module.exports = {
mode: 'production',
optimization: {
minimizer: [
new UglifyJsPlugin({
cache: true,
parallel: true,
sourceMap: true,
uglifyOptions: {
compress: {
drop_console: true,
},
output: {
comments: false,
},
},
}),
],
},
};