Strip comments from CSS
npm install strip-css-comments> Strip comments from CSS
Also available as a Gulp/Grunt/Broccoli plugin.
```
$ npm install strip-css-comments
`js
import stripCssComments from 'strip-css-comments';
// By default important comments /*! are preserved
stripCssComments('/!
//=> '/!
// preserve: false will strip all comments including /*!
stripCssComments(
'/!
{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: comment => comment.charAt(0) === '#'
}
);
//=> '/# preserved / body { color: hotpink; }'
`
Type: string
String with CSS.
Type: object
Type: boolean | RegExp | Function\true
Default:
- 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.
Type: boolean\true
Default:
Replace comments with whitespace instead of stripping them entirely.
```
$ npm run bench
- strip-css-comments-cli - CLI for this module
- strip-json-comments - Strip comments from JSON