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-cleanupVerified import paths — ran on the pinned version, not inferred.
Shows typical usage with Rollup: import cleanup plugin, apply with common options, and bundle.
Remove `acornOptions`, `ecmaVersion`, and `sourceType` from the plugin options object.
Replace `normalizeEols` with `lineEndings` property.
Set `extensions: ['.ts', '.tsx', '.js', '.jsx', '.mjs']` in the options.
Place the `cleanup()` plugin after transpiler plugins in the `plugins` array.
Review documentation for valid comment filters; test with a sample file to verify desired behavior.
Ensure your Rollup pipeline handles async plugins correctly (Rollup >=0.48 supports async).
Set `sourcemap: true` in the plugin options and ensure Rollup's output option includes `sourcemap: true`.
Use `import cleanup from 'rollup-plugin-cleanup'` or `const cleanup = require('rollup-plugin-cleanup')`.Run `npm install rollup-plugin-cleanup --save-dev` or `yarn add rollup-plugin-cleanup -D`.