postcss-discard-comments
TypeScript icon, indicating that this package has built-in type declarations

7.0.4 • Public • Published

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

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
7.0.4378,527latest
5.0.0-rc.2212next
4.0.0-nightly.2020.2.623nightly

Version History

VersionDownloads (Last 7 Days)Published
7.0.4378,527
7.0.31,221,051
7.0.229,855
7.0.1109,888
7.0.048,933
6.0.21,788,321
6.0.1147,352
6.0.0298,859
5.1.24,854,776
5.1.1160,889
5.1.08,883
5.0.328,295
5.0.240,493
5.0.1261,181
5.0.014,177
5.0.0-rc.2212
5.0.0-rc.13
5.0.0-rc.02
5.0.0-alpha.01
4.0.0-nightly.2020.2.623
4.0.0-nightly.2020.1.112
4.0.0-nightly.2020.1.91
4.0.0-nightly.2020.10.202
4.0.0-nightly.2020.9.9128
4.0.0-nightly.2020.9.31
4.0.0-nightly.2020.9.10
4.0.0-nightly.2020.8.290
4.0.0-nightly.2020.8.251
4.0.0-nightly.2020.8.243
4.0.0-nightly.2020.8.172
4.0.0-nightly.2020.8.106
4.0.0-nightly.2020.8.42
4.0.0-nightly.2020.8.12
4.0.0-nightly.2020.7.311
4.0.0-nightly.2020.7.253
4.0.0-nightly.2020.7.241
4.0.22,220,757
4.0.122,776
4.0.03,194
4.0.0-rc.226
4.0.0-rc.06
2.0.4383,493
2.0.315
2.0.228
2.0.15
2.0.04
1.2.14,220
1.2.05
1.1.36
1.1.26
1.1.13
1.1.03
1.0.24
1.0.13
1.0.03

Package Sidebar

Install

npm i postcss-discard-comments

Weekly Downloads

12,026,433

Version

7.0.4

License

MIT

Unpacked Size

13.3 kB

Total Files

12

Last publish

Collaborators

  • beneb
  • trysound
  • ludovicofischer
  • ai
  • chriseppstein
  • andyjansson
  • evilebottnawi
  • cssnano-bot