postcss-discard-comments
Discard comments in your CSS files with PostCSS.
Last updated 7 years ago by beneb .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install postcss-discard-comments 
SYNC missed versions from official npm registry.

postcss-discard-comments

Discard comments in your CSS files with PostCSS.

Install

With npm do:

npm install postcss-discard-comments --save

Example

Input

h1/* heading */{
    margin: 0 auto
}

Output

h1 {
    margin: 0 auto
}

This module discards comments from your CSS files; by default, it will remove all regular comments (/* comment */) and preserve comments marked as important (/*! important */).

Note that this module does not handle source map comments because they are not available to it; PostCSS handles this internally, so if they are removed then you will have to configure source maps in PostCSS.

API

comments([options])

options

remove(function)

Type: function Return: boolean Variable: comment contains a comment without /**/

For each comment, return true to remove, or false to keep the comment.

function(comment) {}
var css = '/* headings *//*@ h1 */h1{margin:0 auto}/*@ h2 */h2{color:red}';
console.log(postcss(comments({
    remove: function(comment) { return comment[0] == "@"; }
})).process(css).css);
//=> /* headings */h1{margin:0 auto}h2{color:red}

NOTE: If you use the remove function other options will not be available.

removeAll

Type: boolean Default: false

Remove all comments marked as important.

var css = '/*! heading */h1{margin:0 auto}/*! heading 2 */h2{color:red}';
console.log(postcss(comments({removeAll: true})).process(css).css);
//=> h1{margin:0 auto}h2{color:red}
removeAllButFirst

Type: boolean Default: false

Remove all comments marked as important, but the first one.

var css = '/*! heading */h1{margin:0 auto}/*! heading 2 */h2{color:red}';
console.log(postcss(comments({removeAllButFirst: true})).process(css).css);
//=> /*! heading */h1{margin:0 auto}h2{color:red}

Usage

See the PostCSS documentation for examples for your environment.

Contributors

See CONTRIBUTORS.md.

License

MIT © Ben Briggs

Current Tags

  • 7.0.3                                ...           latest (2 months ago)
  • 5.0.0-rc.2                                ...           next (4 years ago)
  • 4.0.0-nightly.2020.2.6                                ...           nightly (4 years ago)

54 Versions

  • 7.0.3                                ...           2 months ago
  • 7.0.2                                ...           3 months ago
  • 7.0.1                                ...           5 months ago
  • 7.0.0                                ...           7 months ago
  • 6.0.2                                ...           8 months ago
  • 6.0.1                                ...           a year ago
  • 6.0.0                                ...           2 years ago
  • 5.1.2                                ...           2 years ago
  • 5.1.1                                ...           3 years ago
  • 5.1.0                                ...           3 years ago
  • 5.0.3                                ...           3 years ago
  • 5.0.2                                ...           3 years ago
  • 5.0.1                                ...           3 years ago
  • 5.0.0                                ...           4 years ago
  • 5.0.0-rc.2                                ...           4 years ago
  • 5.0.0-rc.1                                ...           4 years ago
  • 5.0.0-rc.0                                ...           4 years ago
  • 5.0.0-alpha.0                                ...           4 years ago
  • 4.0.0-nightly.2020.2.6                                ...           4 years ago
  • 4.0.0-nightly.2020.1.11                                ...           4 years ago
  • 4.0.0-nightly.2020.1.9                                ...           4 years ago
  • 4.0.0-nightly.2020.10.20                                ...           4 years ago
  • 4.0.0-nightly.2020.9.9                                ...           4 years ago
  • 4.0.0-nightly.2020.9.3                                ...           4 years ago
  • 4.0.0-nightly.2020.9.1                                ...           4 years ago
  • 4.0.0-nightly.2020.8.29                                ...           4 years ago
  • 4.0.0-nightly.2020.8.25                                ...           4 years ago
  • 4.0.0-nightly.2020.8.24                                ...           4 years ago
  • 4.0.0-nightly.2020.8.17                                ...           4 years ago
  • 4.0.0-nightly.2020.8.10                                ...           4 years ago
  • 4.0.0-nightly.2020.8.4                                ...           4 years ago
  • 4.0.0-nightly.2020.8.1                                ...           4 years ago
  • 4.0.0-nightly.2020.7.31                                ...           4 years ago
  • 4.0.0-nightly.2020.7.25                                ...           4 years ago
  • 4.0.0-nightly.2020.7.24                                ...           4 years ago
  • 4.0.2                                ...           6 years ago
  • 4.0.1                                ...           6 years ago
  • 4.0.0                                ...           6 years ago
  • 4.0.0-rc.2                                ...           7 years ago
  • 4.0.0-rc.0                                ...           7 years ago
  • 2.0.4                                ...           9 years ago
  • 2.0.3                                ...           9 years ago
  • 2.0.2                                ...           9 years ago
  • 2.0.1                                ...           9 years ago
  • 2.0.0                                ...           9 years ago
  • 1.2.1                                ...           9 years ago
  • 1.2.0                                ...           9 years ago
  • 1.1.3                                ...           9 years ago
  • 1.1.2                                ...           10 years ago
  • 1.1.1                                ...           10 years ago
  • 1.1.0                                ...           10 years ago
  • 1.0.2                                ...           10 years ago
  • 1.0.1                                ...           10 years ago
  • 1.0.0                                ...           10 years ago
Maintainers (2)
Downloads
Total 4
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 2
Dependencies (1)
Dev Dependencies (4)

© 2010 - cnpmjs.org x YWFE | Home | YWFE