Registry / devops / rollup-plugin-cleanup

rollup-plugin-cleanup

JSON →
library3.2.1jsnpmunverified

Rollup plugin for removing JavaScript comments, compacting empty lines, trimming trailing spaces, and normalizing line endings. Current stable version 3.2.1 supports Rollup >=2.0 and Node.js >=10.14.2 or >=12.0.0. Unlike minifiers like Uglify, it preserves coding style and gives fine-grained control over comment removal via configurable filters. Since v3.1, it no longer depends on acorn, relying instead on js-cleanup. Offers TypeScript definitions, sourcemap support, and works with JS-like files (TS, Flow, React, ES9+).

npm install rollup-plugin-cleanup
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-CLEA
R
rollup-plugin-cleanup
devopsjavascriptv3.2.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import cleanup from 'rollup-plugin-cleanup'
import { cleanup } from 'rollup-plugin-cleanup'
Default export only; named import with braces is incorrect and returns undefined.
rollup-plugin-cleanup
const cleanup = require('rollup-plugin-cleanup')
const { cleanup } = require('rollup-plugin-cleanup')
For CommonJS, the module exports a single function; destructuring is not correct.
Plugin type
import type { RollupPluginCleanupOptions } from 'rollup-plugin-cleanup'
TypeScript types are exported for the options interface; use type import for type-checking.

Shows typical usage with Rollup: import cleanup plugin, apply with common options, and bundle.

import cleanup from 'rollup-plugin-cleanup'; import { rollup } from 'rollup'; import nodeResolve from '@rollup/plugin-node-resolve'; (async () => { const bundle = await rollup({ input: 'src/index.js', plugins: [ nodeResolve(), cleanup({ comments: 'some', // keep some comments (default) compactComments: false, // preserve whitespace in multiline comments maxEmptyLines: 1, // allow at most 1 empty line lineEndings: 'unix', // normalize to Unix line endings extensions: ['js', 'jsx'], // only process these file types sourcemap: true // generate sourcemap }) ] }); await bundle.write({ file: 'dist/bundle.js', format: 'esm' }); })();
Debug
Known issues
breakingv3.0.0 drops the `acornOptions`, `ecmaVersion`, and `sourceType` options; they are ignored if provided. Remove them from your config.
fix
Remove `acornOptions`, `ecmaVersion`, and `sourceType` from the plugin options object.
affects: >=3.0.0
deprecatedThe `normalizeEols` option is deprecated in v3.1.0 and ignored in v3.2.0. Use `lineEndings` instead.
fix
Replace `normalizeEols` with `lineEndings` property.
affects: >=3.1.0
gotchaBy default, the plugin processes only .js, .jsx, and .mjs files. If you process TypeScript or other extensions, you must set the `extensions` option explicitly.
fix
Set `extensions: ['.ts', '.tsx', '.js', '.jsx', '.mjs']` in the options.
affects: >=3.0.0
gotchaThe plugin is designed as a post-processor and should run after transpilers (e.g., Babel, TypeScript). Running it before may break type annotations or syntax not yet compiled.
fix
Place the `cleanup()` plugin after transpiler plugins in the `plugins` array.
affects: >=0.1.0
gotchaThe `comments` option accepts special strings 'all' or 'none', but also filter patterns. Using invalid patterns may cause all comments to be removed unexpectedly.
fix
Review documentation for valid comment filters; test with a sample file to verify desired behavior.
affects: >=1.0.0
breakingv2.0.0 changed plugin operation to async (returns Promise). If you are chaining with synchronous code, you may need to adapt.
fix
Ensure your Rollup pipeline handles async plugins correctly (Rollup >=0.48 supports async).
affects: >=2.0.0 <3.0.0
Errors
Common errors & fixes
Error: The 'cleanup' plugin is not generating a sourcemap
The `sourcemap` option is set to `false` by default? Actually default is true, but if Rollup's `sourceMap` option is set to false, the plugin may not output a sourcemap.
fix
Set `sourcemap: true` in the plugin options and ensure Rollup's output option includes `sourcemap: true`.
TypeError: cleanup is not a function
Importing the module incorrectly; using named import instead of default import.
fix
Use `import cleanup from 'rollup-plugin-cleanup'` or `const cleanup = require('rollup-plugin-cleanup')`.
Error: Cannot find module 'rollup-plugin-cleanup'
Package not installed or missing from node_modules.
fix
Run `npm install rollup-plugin-cleanup --save-dev` or `yarn add rollup-plugin-cleanup -D`.
Upgrade
Version history
3.2.1latest on npm
Audit
Dependencies
rolluprequiredPeer dependency - requires Rollup >=2.0
js-cleanuprequiredCore dependency for comment removal and code cleanup
Agent activity
7 hits · last 30 days
node
6
Resources
rollup-plugin-cleanup — npm install rollup-plugin-cleanup · libregistry