Strip comments from CSS
Also available as a Gulp/Grunt/Broccoli plugin.
Usage
$ npm install strip-css-comments
Usage
import stripCssComments from 'strip-css-comments';
stripCssComments('/*! <copyright> */ body { /* unicorns */color: hotpink; }');
stripCssComments(
'/*! <copyright> */ body { /* unicorns */color: hotpink; }',
{preserve: false}
);
stripCssComments(
'/*# preserved */ body { /* unicorns */color: hotpink; }',
{preserve: /^#/}
);
stripCssComments(
'/*# preserved */ body { /* unicorns */color: hotpink; }',
{
preserve: comment => comment.charAt(0) === '#'
}
);
API
cssString
Type: string
String with CSS.
options
Type: object
preserve
Type: boolean | RegExp | Function
Default: true
true
- Preserve important comments /*! */
.false
- Strip all comments.RegExp
- Preserve comments where the comment body matches a regular expression.Function
- Preserve comments for which a function returns true
. The function is called on each comment, gets the comment body as the first argument, and is expected to return a boolean of whether to preserve the comment.
whitespace
Type: boolean
Default: true
Replace comments with whitespace instead of stripping them entirely.
Benchmark
$ npm run bench
Related