rollup-plugin-minify
raw JSON → 1.0.3 verified Mon Apr 27 auth: no javascript maintenance
A Rollup plugin that generates minified output files using UglifyJS, creating separate .min.js files with source maps. Version 1.0.3, last updated in 2017. It hooks into Rollup's ongenerate event to minify specific output formats (e.g., iife, cjs) after generation. Different from rollup-plugin-uglify which replaces the original output, this plugin creates additional files. Limited to UglifyJS (no Terser support) and has no updates since 2017.
Common errors
error TypeError: minify is not a function ↓
cause Trying to use destructured import on a default export.
fix
Use
import minify from 'rollup-plugin-minify' instead of import { minify } from ... error Error: The 'dest' option must be a string ↓
cause Passing an object without a 'dest' property or incorrect type.
fix
Ensure each format option is either a string (dest) or an object with a 'dest' string property.
error Error: Cannot find module 'uglify-js' ↓
cause uglify-js is a peer dependency not automatically installed.
fix
Run
npm install uglify-js alongside rollup-plugin-minify. Warnings
deprecated Uses UglifyJS (not Terser) which is outdated for ES6+ code. ↓
fix Consider using rollup-plugin-terser or @rollup/plugin-terser for modern JavaScript.
gotcha Options are per-format (e.g., iife, cjs) not global. Passing a string as value sets dest option. ↓
fix Use object form for advanced options: { iife: { dest: 'file.min.js', mangle: false } }
gotcha Output files are written by the plugin itself, not by Rollup's output options. Ensure no conflicts. ↓
fix Do not specify the same file in both the plugin and Rollup output.file.
gotcha Only works with formats iife, cjs, es, amd, umd. Other formats may not produce files. ↓
fix Check the format matches one of these or test output.
Install
npm install rollup-plugin-minify yarn add rollup-plugin-minify pnpm add rollup-plugin-minify Imports
- default wrong
import { minify } from 'rollup-plugin-minify'correctimport minify from 'rollup-plugin-minify' - default (CommonJS) wrong
const { minify } = require('rollup-plugin-minify')correctconst minify = require('rollup-plugin-minify') - usage wrong
minify({ dest: 'bundle.min.js' })correctminify({ iife: 'iife.min.js', cjs: 'cjs.min.js' })
Quickstart
import { rollup } from 'rollup';
import minify from 'rollup-plugin-minify';
rollup({
input: 'src.js',
plugins: [
minify({ iife: 'iife.min.js', cjs: 'cjs.min.js' })
]
}).then(bundle => {
// bundle generated
});