node package manager


Build Status Test Coverage npm Version License


Rollup plugin to remove comments, trim trailing spaces, compact empty lines, and normalize line endings in JavaScript files.

With cleanup, you have:

  • Removal of JavaScript comments through powerful filters (configurable)*
  • Normalization of line endings (Unix, Mac, or Windows)
  • Empty lines compactation (configurable)
  • Remotion of trailing spaces
  • Source Map support


Because rollup is a JavaScript bundler and cleanup is a JavaScript post-processor, it should work with any JavaScript dialect handled by rollup, but you need put cleanup last in your plugin list.

Why not Uglify?

Uglify is a excelent minifier but you have little control over the results, while with cleanup your coding style remains intact and removal of comments is strictly under your control.


npm install rollup-plugin-cleanup --save-dev


import { rollup } from 'rollup';
import awesome from 'rollup-plugin-awesome';
import cleanup from 'rollup-plugin-cleanup';
  entry: 'src/main.js',
  plugins: [
    awesome(),        // other plugins 
    cleanup()         // cleanup here 

That's it.

You can restrict the accepted files using the options "include", "exclude", and "extensions" (see below). By default, only the .js, .jsx, and .tag files are processed, but it can be useful for any non-binary file if you skip the JS parsing by setting the option comments: 'all' in the plugin and include option with the desired extensions.


Name Default Description
comments 'some' Filter or array of filter names and/or regexes. Use "all" to keep all, or "none" to remove all the comments.
maxEmptyLines 0 Use a positive value or -1 to keep all the lines.
normalizeEols unix Allowed values: "unix", "mac", "win".
sourceType 'module' For the parser, change it to "script" if necessary.
include '' minimatch or array of minimatch patterns for paths to include in the process.
exclude '' minimatch or array of minimatch patterns for paths to exclude in the process.
extensions ['.js', '.jsx', '.tag'] String or array of strings with extensions of files to process.

* Source Map support is given through the Rollup sourceMap option.

Predefined Comment Filters

Se the regexes in src/parse-options.js

Name Site/Description
license Preserve comments with "@license" inside.
some Like the uglify default: "@license", "@preserve", "@cc_on"
jsdoc JSDoc tags
jslint JSLint directives
jshint JSHint directives
eslint ESLint directives
ts3s: TypeScript Triple-Slash Directives
jscs jscs instructions
istanbul istanbul comments
srcmaps Source Map (inlined or external)

Custom Filters

You can set custom filters through regexes that matches the content of the comments that you want to preserve (multiline comments begins with an asterisk (*), one-line comments begins with a slash (/)).


This filter will preserve multiline comments starting with a dash, in addition to eslint directives:

  plugins: [
      comments: ['eslint', /^\*-/]

What's New

  • New filter "ts3s" to preserve TypeScript Triple-Slash Directives (See NOTE)
  • Closes #5 : cleanup didn't generate a sourcemap for the transformation.


TypeScript source must be already compiled to JavaScript.

* For me, write in english is 10x harder than coding JS, so contributions are welcome...