Strip comments from CSS
Also available as a gulp/grunt/broccoli plugin.
Usage
$ npm install --save strip-css-comments
var stripCssComments = require('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: function (comment) {
return comment.charAt(0) === '#';
}
}
);
API
input
Required
Type: string
String with CSS.
options
preserve
Type: boolean
, RegExp
, function
Default: true
true
- Preserve comments that use the /*! */
syntaxfalse
- Strip all commentsRegExp
- 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.
Benchmark
$ npm run bench
Related
License
MIT © Sindre Sorhus