Strip comments from CSS
Also available as a gulp/grunt/broccoli plugin.
$ npm install --save strip-css-comments
var stripCssComments = require('strip-css-comments');
// by default important comments `/*!` are preserved
stripCssComments('/*! <copyright> */ body { /* unicorns */color: hotpink; }');
//=> '/*! <copyright> */ body { color: hotpink; }'
// `preserve: false` will strip all comments including `/*!`
stripCssComments(
'/*! <copyright> */ body { /* unicorns */color: hotpink; }',
{preserve: false}
);
//=> 'body { color: hotpink; }'
// preserve comments based on a regex
stripCssComments(
'/*# preserved */ body { /* unicorns */color: hotpink; }',
{preserve: /^#/}
);
//=> '/*# preserved */ body { color: hotpink; }'
// preserve comments based on the return value of the supplied function
stripCssComments(
'/*# preserved */ body { /* unicorns */color: hotpink; }',
{
preserve: function (comment) {
return comment.charAt(0) === '#';
}
}
);
//=> '/*# preserved */ body { color: hotpink; }'
Required
Type: string
String with CSS.
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 returnstrue
. 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.
$ npm run bench
- strip-css-comments-cli - CLI for this module
- strip-json-comments - Strip comments from JSON
MIT © Sindre Sorhus