3.2.1 • Published 4 years ago

rollup-plugin-cleanup v3.2.1

Weekly downloads
26,158
License
MIT
Repository
github
Last release
4 years ago

rollup-plugin-cleanup

npm Version License AppVeyor Status Travis Status Maintainability Coverage

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

With the rollup-plugin-cleanup you have:

  • Compaction of empty lines within multiline comments and/or out of them.
  • Normalization of line endings to Unix, Mac, or Windows.
  • Removal of JavaScript comments through powerful, configurable filters.
  • Removal of trailing whitespace of each line.
  • TypeScript definitions.
  • Sourcemap support.

From v3.1, this plugin no longer uses acorn. See more in the Whats New section.

rollup-plugin-cleanup requires node v10.13 or above, but avoid the buggy v11.x

Important:

rollup-plugin-cleanup is based on js-cleanup and can handle any JS-like file: TypeScript, Flow, React, ES9, etc, but it is mainly a postprocessor, so it should be runned in a later stage of your toolchain, after any preprocessor or transpiler.

Why not Uglify?

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

Support my Work

I'm a full-stack developer with more than 20 year of experience and I try to share most of my work for free and help others, but this takes a significant amount of time and effort so, if you like my work, please consider...

Of course, feedback, PRs, and stars are also welcome 🙃

Thanks!

Install

npm install rollup-plugin-cleanup --save-dev
# or with yarn
yarn add rollup-plugin-cleanup -D

Usage

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

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

That's it.

By default, only the .js, .jsx, and .tag files are processed, but you can expand or restrict the set of accepted files using the options include, exclude, and extensions (see below).

Options

From v3.1.0 normalizeEols is deprecated in favor of lineEndings and the properties ecmaVersion, sourceType, and acornOptions are ignored. See more in Whats New section.

NameDefaultDescription
comments'some'Filter or array of filters that determinates which comments should be preserved.Use "all" to keep all, or "none" to remove all the comments.
compactCommentstrueShould js-cleanup also compact whitespace and blank lines in the preserved multiline comments?Line-ending normalization is always done.
lineEndingsunixType of Line-ending for normalization: "unix", "mac", "win".
maxEmptyLines0Maximum successive empty lines to preserve in the output.Use a positive value, or -1 to keep all the lines.
sourcemaptrueShould a sourcemap be generated?
extensions['js', 'jsx', 'mjs']String or array of strings with extensions of files to process.
exclude(none)picomatch or array of picomatch patterns for paths to exclude of the process.
include(none)picomatch or array of picomatch patterns for paths to include in the process.

Predefined Comment Filters

Instead the special 'all' or 'none' keywords, you can use any combination of custom filters along with any of these predefined ones:

NameWill preserve...
someComments containing "@license", "@preserve", or starting with "!".
licenseComments containing "@license".
eslintESLint directives.
flowFacebook Flow directives, comment types, and flowlint comments.
istanbulistanbul ignore comments.
jsdocJSDoc comments.
jshintJSHint directives.
jslintJSLint directives.
sourcesSourcemap directives sourceURL and sourceMappingURL.
tsMS TypeScript Triple-Slash and @ts-* directives, plus the @jsx pragma.
ts3sTypeScript Triple-Slash directives.

From v3.1.0, some does not includes '@cc_on' and the jscs filter was deprecated. See more in Whats New section.

'srcmaps' will be preserved as an alias to the 'sources' filter.

See the regexes in the js-cleanup src/predef-filters.ts file.

Custom Filters

You can set custom filters through regexes that matches the content of the comments that you want to preserve.

The string to which the regex is applied does not includes the first slash, nor the */ terminator of the multiline comments, so the multiline comments begins with an asterisk (*) and single-line comments begins with a slash (/).

For example, the following filters will preserve ESLint directives and multiline comments starting with a dash:

const cleanedCode = jsCleanup(code, null, { comments: ['eslint', /^\*-/] })

What's New

Changes in v3.2.1

  • Fixed #16 ? Thanks to @Aqours, @gevalo1 & @xania for repoting this issue
  • Using js-cleanup v1.2.0 and Rollup v2.0+
  • Requires NodeJS v10.14.2 or v12.0 and above
  • Updated dependencies

License

The MIT License (MIT)

© 2018-2020 Alberto Martínez

findhotel-sapissr-engine@infinitebrahmanuniverse/nolb-rollup-plugin-cgdcxapicontrol1@everything-registry/sub-chunk-2680@alt-research/devautographqlsgs-monitortablerwiz-editor-testwindy-plugin-sun-positionwindy-plugin-tjv23windy-plugin-trajwindyplugin-module-airspaceswindyplugin-module-infoboxwindyplugin-module-pickertoolswindyplugin-module-rplanner-wrapperwjl-utilswindy-plugin-minitransatwindy-plugin-open-pluginswindy-plugin-other-pickerwindy-plugin-picker2windy-plugin-primonial-trackerwindy-plugin-regattwindy-plugin-resourceswindy-plugin-routingwindy-plugin-skewtwindy-plugin-airspaceswindy-plugin-aucb24windy-plugin-dawindy-plugin-day-nightwindy-plugin-ext-dep-testwindy-plugin-flymetwindy-plugin-fpwindy-plugin-globewindy-plugin-6cbaeq0nfx30qlfcq4lnp1olk4kpfzvw-plugin-methodwagashiwdh-monitoringsdkweiyie-toolsxdata-vue-excelxlj-utilsxiaoyao-utilsreact-webpack-to-vite-envrollup-plugin-cleanup-chunksublinerollup-to-nejrollup-toolkitremaputilssuperadmin-utilsthe-wind-blows-toolsthingssdk-espruino-strategyvideo-indexeddbcomponent-library111plpuse-utilsaugnitoambientsdk_test1lin-utils_dateliilibjin-toolhuntersofbookhld-libshuan-utilshzc-public-utilhaixu-utilsgxf-utils-eskalos-script-starterjie-openlayersleagformgis-login-npmgo-corelxy_lodash_tspadlopen-toolkitopenlayersout-put-time-pluginppnnssy-date-utilspreuppsz-builderpk-trackpreload-inline-html-pluginpritestreactqwertynewsdkdemo-publishnewchain-web3-utilspersagy-utilsreact-event-basenpm-personal-toolstring-urlss_tool_libraryrollup-config-buildersirlibreactsimonelastackagesimple-reduceslrc-element-tiptapsketch-buildertldashuseglobalsutils-nxhl-sztin-custom-utils@battr/battr-build@bdefore/nivo-patterned-radial-arc
3.2.1

4 years ago

3.2.0

4 years ago

3.1.1

6 years ago

3.1.0

6 years ago

3.0.0

6 years ago

3.0.0-beta.1

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago