{"id":21950,"library":"rollup-plugin-cleanup","title":"rollup-plugin-cleanup","description":"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+).","status":"active","version":"3.2.1","language":"javascript","source_language":"en","source_url":"https://github.com/aMarCruz/rollup-plugin-cleanup","tags":["javascript","rollup","rollup-plugin","es6","modules","comments","removal","cleanup"],"install":[{"cmd":"npm install rollup-plugin-cleanup","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-cleanup","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-cleanup","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency - requires Rollup >=2.0","package":"rollup","optional":false},{"reason":"Core dependency for comment removal and code cleanup","package":"js-cleanup","optional":false}],"imports":[{"note":"Default export only; named import with braces is incorrect and returns undefined.","wrong":"import { cleanup } from 'rollup-plugin-cleanup'","symbol":"default","correct":"import cleanup from 'rollup-plugin-cleanup'"},{"note":"For CommonJS, the module exports a single function; destructuring is not correct.","wrong":"const { cleanup } = require('rollup-plugin-cleanup')","symbol":"rollup-plugin-cleanup","correct":"const cleanup = require('rollup-plugin-cleanup')"},{"note":"TypeScript types are exported for the options interface; use type import for type-checking.","wrong":null,"symbol":"Plugin type","correct":"import type { RollupPluginCleanupOptions } from 'rollup-plugin-cleanup'"}],"quickstart":{"code":"import cleanup from 'rollup-plugin-cleanup';\nimport { rollup } from 'rollup';\nimport nodeResolve from '@rollup/plugin-node-resolve';\n\n(async () => {\n  const bundle = await rollup({\n    input: 'src/index.js',\n    plugins: [\n      nodeResolve(),\n      cleanup({\n        comments: 'some',          // keep some comments (default)\n        compactComments: false,    // preserve whitespace in multiline comments\n        maxEmptyLines: 1,          // allow at most 1 empty line\n        lineEndings: 'unix',       // normalize to Unix line endings\n        extensions: ['js', 'jsx'], // only process these file types\n        sourcemap: true            // generate sourcemap\n      })\n    ]\n  });\n  await bundle.write({ file: 'dist/bundle.js', format: 'esm' });\n})();","lang":"typescript","description":"Shows typical usage with Rollup: import cleanup plugin, apply with common options, and bundle."},"warnings":[{"fix":"Remove `acornOptions`, `ecmaVersion`, and `sourceType` from the plugin options object.","message":"v3.0.0 drops the `acornOptions`, `ecmaVersion`, and `sourceType` options; they are ignored if provided. Remove them from your config.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Replace `normalizeEols` with `lineEndings` property.","message":"The `normalizeEols` option is deprecated in v3.1.0 and ignored in v3.2.0. Use `lineEndings` instead.","severity":"deprecated","affected_versions":">=3.1.0"},{"fix":"Set `extensions: ['.ts', '.tsx', '.js', '.jsx', '.mjs']` in the options.","message":"By default, the plugin processes only .js, .jsx, and .mjs files. If you process TypeScript or other extensions, you must set the `extensions` option explicitly.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Place the `cleanup()` plugin after transpiler plugins in the `plugins` array.","message":"The 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.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Review documentation for valid comment filters; test with a sample file to verify desired behavior.","message":"The `comments` option accepts special strings 'all' or 'none', but also filter patterns. Using invalid patterns may cause all comments to be removed unexpectedly.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure your Rollup pipeline handles async plugins correctly (Rollup >=0.48 supports async).","message":"v2.0.0 changed plugin operation to async (returns Promise). If you are chaining with synchronous code, you may need to adapt.","severity":"breaking","affected_versions":">=2.0.0 <3.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Set `sourcemap: true` in the plugin options and ensure Rollup's output option includes `sourcemap: true`.","cause":"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.","error":"Error: The 'cleanup' plugin is not generating a sourcemap"},{"fix":"Use `import cleanup from 'rollup-plugin-cleanup'` or `const cleanup = require('rollup-plugin-cleanup')`.","cause":"Importing the module incorrectly; using named import instead of default import.","error":"TypeError: cleanup is not a function"},{"fix":"Run `npm install rollup-plugin-cleanup --save-dev` or `yarn add rollup-plugin-cleanup -D`.","cause":"Package not installed or missing from node_modules.","error":"Error: Cannot find module 'rollup-plugin-cleanup'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}