@lopatnov/rollup-plugin-uglify
v4.1.3
Published
A Rollup plugin for minifying JavaScript bundles using Terser
Maintainers
Readme
@lopatnov/rollup-plugin-uglify
A Rollup plugin for minifying JavaScript bundles using Terser. Full TypeScript support, multiple output formats, flexible file filtering, zero configuration required for basic usage.
Table of Contents
Installation
Prerequisites
This plugin requires Rollup and Terser as peer dependencies:
npm install rollup terser --save-devInstall the plugin
npm install @lopatnov/rollup-plugin-uglify --save-devUsage
Basic Usage
// rollup.config.js
import uglify from "@lopatnov/rollup-plugin-uglify";
export default {
input: "src/index.js",
output: {
file: "dist/bundle.js",
format: "cjs",
},
plugins: [uglify()],
};With Options
import uglify from "@lopatnov/rollup-plugin-uglify";
export default {
input: "src/index.js",
output: {
file: "dist/bundle.js",
format: "es",
sourcemap: true,
},
plugins: [
uglify({
compress: {
drop_console: true,
drop_debugger: true,
},
mangle: true,
ecma: 2020,
}),
],
};CommonJS Import
const uglify = require("@lopatnov/rollup-plugin-uglify");Options
The uglify() function accepts an optional configuration object that extends Terser's MinifyOptions.
Plugin-specific Options
| Option | Type | Default | Description |
| --------- | ------------------------------ | ------------- | ---------------------------------------------------------------------------------- |
| include | string \| RegExp | - | Pattern to match chunks that should be minified |
| exclude | string \| RegExp | - | Pattern to match chunks that should be skipped |
| hook | "renderChunk" \| "transform" | "transform" | Rollup hook to use for minification. It's recommended to use "renderChunk" value |
Common Terser Options
| Option | Type | Default | Description |
| ----------- | --------- | ------- | -------------------------------------------------------- |
| sourceMap | boolean | auto | Generate source maps (follows output sourcemap option) |
| compress | object | - | Compression options |
| mangle | boolean | - | Mangle variable names |
| ecma | number | - | ECMAScript version (2015, 2020, etc.) |
For a complete list of options, see the Terser documentation.
Examples
Minify only specific files:
uglify({ include: /\.min\.js$/ });Exclude test files:
uglify({ exclude: /\.test\.js$/ });Use legacy transform hook (per-module minification):
uglify({ hook: "transform", compress: true });Production build with aggressive compression:
uglify({
compress: {
drop_console: true,
drop_debugger: true,
pure_funcs: ["console.log"],
},
mangle: { properties: false },
ecma: 2020,
});Troubleshooting
Cannot find module @rollup/pluginutils
If you're upgrading from version 2.1.2 to 2.1.4+, the dependency has been updated from rollup-pluginutils to @rollup/pluginutils. Run npm install to resolve.
Contributing
Contributions are welcome! Please read CONTRIBUTING.md before opening a pull request.
- Bug reports → open an issue
- Questions → Discussions
- Found it useful? A star on GitHub helps others discover the project
Built With
- TypeScript — strict typing throughout
- Rollup — bundled to ESM, CJS, and UMD formats
- Terser — JavaScript minification engine
- @rollup/pluginutils — include/exclude pattern filtering
- Jest — unit testing with coverage
License
Apache-2.0 © 2019–2026 Oleksandr Lopatnov · LinkedIn
