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

4.0.0-rc.2 • 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.4618,032latest
5.0.0-rc.2223next
4.0.0-nightly.2020.2.652nightly

Version History

VersionDownloads (Last 7 Days)Published
7.0.4618,032
7.0.3938,680
7.0.228,060
7.0.186,895
7.0.041,114
6.0.21,747,408
6.0.1135,990
6.0.0275,756
5.1.24,740,056
5.1.1184,488
5.1.012,420
5.0.331,061
5.0.235,563
5.0.1221,623
5.0.012,573
5.0.0-rc.2223
5.0.0-rc.10
5.0.0-rc.02
5.0.0-alpha.00
4.0.0-nightly.2020.2.652
4.0.0-nightly.2020.1.111
4.0.0-nightly.2020.1.90
4.0.0-nightly.2020.10.201
4.0.0-nightly.2020.9.91
4.0.0-nightly.2020.9.30
4.0.0-nightly.2020.9.10
4.0.0-nightly.2020.8.290
4.0.0-nightly.2020.8.250
4.0.0-nightly.2020.8.240
4.0.0-nightly.2020.8.170
4.0.0-nightly.2020.8.100
4.0.0-nightly.2020.8.41
4.0.0-nightly.2020.8.11
4.0.0-nightly.2020.7.311
4.0.0-nightly.2020.7.252
4.0.0-nightly.2020.7.240
4.0.22,126,355
4.0.111,825
4.0.02,453
4.0.0-rc.235
4.0.0-rc.00
2.0.4371,794
2.0.37
2.0.21
2.0.10
2.0.00
1.2.15,001
1.2.00
1.1.31
1.1.21
1.1.10
1.1.00
1.0.20
1.0.11
1.0.00

Package Sidebar

Install

npm i postcss-discard-comments@4.0.0-rc.2

Version

4.0.0-rc.2

License

MIT

Last publish

Collaborators

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