rollup-plugin-uglify

A rollup plugin to minify javascript with Terser

View the Project on GitHub

@lopatnov/rollup-plugin-uglify

npm NPM version License Build Status TypeScript GitHub stars

A Rollup plugin for minifying JavaScript bundles using Terser.

Features

Installation

Prerequisites

This plugin requires Rollup and Terser as peer dependencies:

npm install rollup terser --save-dev

Install the plugin

npm install @lopatnov/rollup-plugin-uglify --save-dev

Usage

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 Description
include string \| RegExp Pattern to match files that should be minified
exclude string \| RegExp Pattern to match files that should be skipped

Common Terser Options

Option Type Default Description
sourceMap boolean true Generate source maps
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$/,
});

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+, you may encounter this error. The dependency has been updated from rollup-pluginutils to @rollup/pluginutils. Run npm install to resolve.

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

License

Apache-2.0

Copyright 2019-2026 Oleksandr Lopatnov


Author

Oleksandr Lopatnov — Full-stack developer

LinkedIn GitHub

If you find this project useful, please consider giving it a star on GitHub!