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
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)
- Normalization of line endings (Unix, Mac, or Windows)
- Empty lines compactation (configurable)
- Remotion of trailing spaces
- 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-devUsage
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.
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.
Options
| 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 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 |
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 (/)).
Example:
This filter will preserve multiline comments starting with a dash, in addition to eslint directives:
...
plugins: [
cleanup({
comments: ['eslint', /^\*-/]
})
]* For me, write in english is 10x harder than coding JS, so contributions are welcome...
[issues-image]: https://img.shields.io/codeclimate/issues/github/aMarCruz/rollup-plugin-cleanup.svg?style=flat-square [issues-url]: https://codeclimate.com/github/aMarCruz/rollup-plugin-cleanup