rollup-plugin-uglify
raw JSON → 6.0.4 verified Mon Apr 27 auth: no javascript
Rollup plugin to minify generated bundles using UglifyJS. Current stable version is 6.0.4, compatible with Rollup >=0.66.0 <2. It runs UglifyJS in a worker per chunk, improving build performance for code-split projects, and displays errors with babel code frames. Supports source maps and configurable number of workers. Note: UglifyJS handles only ES5; for ES6+ use the similar rollup-plugin-terser. This plugin has undergone several breaking changes in major versions, including moving to worker-based uglification (v5) and reverting from uglify-es back to uglify-js (v4).
Common errors
error Error: 'uglify' is not exported from 'rollup-plugin-uglify' ↓
cause Using default import or CommonJS require incorrectly in v4+.
fix
Use named import: import { uglify } from 'rollup-plugin-uglify'
error TypeError: Cannot set property 'numWorkers' of undefined ↓
cause Missing options object or passing invalid workers configuration.
fix
Ensure uglify() is called with an object: uglify({ numWorkers: 2 })
error SyntaxError: Unexpected token: punc ()) ↓
cause UglifyJS cannot parse ES6+ syntax; this plugin only handles ES5.
fix
Use rollup-plugin-terser instead, or transpile code to ES5 first.
Warnings
breaking Default export removed in v4.0.0. Use named import { uglify } instead. ↓
fix import { uglify } from 'rollup-plugin-uglify'
breaking Removed 'minifier' option in v5.0.0. Use rollup-plugin-terser for UglifyES/Terser. ↓
fix Switch to rollup-plugin-terser if you need ES6+ minification.
breaking Renamed 'sourceMap' option to 'sourcemap' in v5.0.0 to match Rollup API. ↓
fix Use { sourcemap: true } instead of { sourceMap: true }
deprecated rollup-plugin-uglify only supports ES5. For ES6+ code, use rollup-plugin-terser. ↓
fix Replace with rollup-plugin-terser if your code contains ES6+ syntax.
gotcha Package requires Rollup >=0.66.0 and <2. It may not work with Rollup v2 or later. ↓
fix Check rollup version; consider using rollup-plugin-terser for Rollup >=2.
Install
npm install rollup-plugin-uglify yarn add rollup-plugin-uglify pnpm add rollup-plugin-uglify Imports
- uglify wrong
const uglify = require('rollup-plugin-uglify')correctimport { uglify } from 'rollup-plugin-uglify' - uglify wrong
import uglify from 'rollup-plugin-uglify'correctimport { uglify } from 'rollup-plugin-uglify' - uglify wrong
const uglify = require('rollup-plugin-uglify')correctconst { uglify } = require('rollup-plugin-uglify')
Quickstart
// Install: npm install --save-dev rollup-plugin-uglify
// rollup.config.js
import { uglify } from 'rollup-plugin-uglify';
export default {
input: 'src/index.js',
output: {
file: 'dist/bundle.js',
format: 'iife'
},
plugins: [
uglify({
sourcemap: true,
numWorkers: 2,
output: {
comments: 'some'
}
})
]
};