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.4870,498latest
5.0.0-rc.2194next
4.0.0-nightly.2020.2.642nightly

Version History

VersionDownloads (Last 7 Days)Published
7.0.4870,498
7.0.3829,259
7.0.231,213
7.0.172,443
7.0.033,024
6.0.21,832,097
6.0.1128,604
6.0.0261,961
5.1.25,153,920
5.1.1228,437
5.1.016,634
5.0.356,979
5.0.242,091
5.0.1300,508
5.0.017,150
5.0.0-rc.2194
5.0.0-rc.11
5.0.0-rc.01
5.0.0-alpha.02
4.0.0-nightly.2020.2.642
4.0.0-nightly.2020.1.111
4.0.0-nightly.2020.1.91
4.0.0-nightly.2020.10.201
4.0.0-nightly.2020.9.91
4.0.0-nightly.2020.9.31
4.0.0-nightly.2020.9.11
4.0.0-nightly.2020.8.291
4.0.0-nightly.2020.8.251
4.0.0-nightly.2020.8.241
4.0.0-nightly.2020.8.171
4.0.0-nightly.2020.8.102
4.0.0-nightly.2020.8.41
4.0.0-nightly.2020.8.12
4.0.0-nightly.2020.7.312
4.0.0-nightly.2020.7.251
4.0.0-nightly.2020.7.242
4.0.22,773,194
4.0.131,064
4.0.05,927
4.0.0-rc.2285
4.0.0-rc.035
2.0.4776,384
2.0.3215
2.0.23
2.0.11
2.0.02
1.2.16,807
1.2.07
1.1.31
1.1.21
1.1.14
1.1.01
1.0.21
1.0.11
1.0.02

Package Sidebar

Install

npm i postcss-discard-comments

Weekly Downloads

12,555,355

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