JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 74585
  • Score
    100M100P100Q170210F
  • License MIT

Rollup plugin to trim trailing spaces, compact empty lines, and normalize line endings

Package Exports

  • rollup-plugin-cleanup

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (rollup-plugin-cleanup) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Build Status AppVeyor Status npm Version License

rollup-plugin-cleanup

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)
  • Empty lines compactation (configurable)
  • Remotion of trailing spaces
  • Normalization of line endings (Unix, Mac, or Windows)
  • Source Map support

IMPORTANT:

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.

Install

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

Usage

import { rollup } from 'rollup';
import awesome from 'rollup-plugin-awesome';
import cleanup from 'rollup-plugin-cleanup';

rollup({
  entry: 'src/main.js',
  plugins: [
    awesome(),        // other plugins
    cleanup()         // cleanup here
  ]
}).then(...)

That's it.

By default, only the .js files are processed, but it can be useful for any non-binary file if you pass the option comments='all' to the plugin. You can restrict the accepted files using the options "include", "exclude", and "extensions" (see below).

Options

Name Default Description
comments ['some'] Regex, array of filter names, "all" to keep all, or "none" to remove all.
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.
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 Filters

Name Regex Site/Description
license /@license\b/ Preserve comments with "@license" inside.
some `/(?:@license @preserve
jsdoc /^\*\*[^@]*@[A-Za-z]/ JSDoc
jslint `/^[/*](?:jslint global
jshint `/^[/*]\s*(?:jshint globals
eslint `/^[/*]\s*(?:eslint(?:\s -env
jscs /^[\/\*]\s*jscs:[ed]/ jscs
istanbul /^[\/\*]\s*istanbul\s/ istanbul
srcmaps /^.[#@]\ssource(?:Mapping)?URL=/ Source Map

TODO

This is work in progress, so please update cleanup constantly, I hope the first stable version does not take too long.

  • 100% test coverage and more tests
  • async mode
  • Configuration from the file system
  • Better documentation*
  • You tell me...

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