You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
2.3 KiB

4 years ago
  1. # [postcss][postcss]-discard-comments
  2. > Discard comments in your CSS files with PostCSS.
  3. ## Install
  4. With [npm](https://npmjs.org/package/postcss-discard-comments) do:
  5. ```
  6. npm install postcss-discard-comments --save
  7. ```
  8. ## Example
  9. ### Input
  10. ```css
  11. h1/* heading */{
  12. margin: 0 auto
  13. }
  14. ```
  15. ### Output
  16. ```css
  17. h1 {
  18. margin: 0 auto
  19. }
  20. ```
  21. This module discards comments from your CSS files; by default, it will remove
  22. all regular comments (`/* comment */`) and preserve comments marked as important
  23. (`/*! important */`).
  24. Note that this module does not handle source map comments because they are not
  25. available to it; PostCSS handles this internally, so if they are removed then
  26. you will have to [configure source maps in PostCSS][maps].
  27. [maps]: https://github.com/postcss/postcss/blob/master/docs/source-maps.md
  28. ## API
  29. ### comments([options])
  30. #### options
  31. ##### remove(function)
  32. Type: `function`
  33. Return: `boolean`
  34. Variable: `comment` contains a comment without `/**/`
  35. For each comment, return true to remove, or false to keep the comment.
  36. ```js
  37. function(comment) {}
  38. ```
  39. ```js
  40. var css = '/* headings *//*@ h1 */h1{margin:0 auto}/*@ h2 */h2{color:red}';
  41. console.log(postcss(comments({
  42. remove: function(comment) { return comment[0] == "@"; }
  43. })).process(css).css);
  44. //=> /* headings */h1{margin:0 auto}h2{color:red}
  45. ```
  46. **NOTE:** If you use the `remove` function other options will not be available.
  47. ##### removeAll
  48. Type: `boolean`
  49. Default: `false`
  50. Remove all comments marked as important.
  51. ```js
  52. var css = '/*! heading */h1{margin:0 auto}/*! heading 2 */h2{color:red}';
  53. console.log(postcss(comments({removeAll: true})).process(css).css);
  54. //=> h1{margin:0 auto}h2{color:red}
  55. ```
  56. ##### removeAllButFirst
  57. Type: `boolean`
  58. Default: `false`
  59. Remove all comments marked as important, but the first one.
  60. ```js
  61. var css = '/*! heading */h1{margin:0 auto}/*! heading 2 */h2{color:red}';
  62. console.log(postcss(comments({removeAllButFirst: true})).process(css).css);
  63. //=> /*! heading */h1{margin:0 auto}h2{color:red}
  64. ```
  65. ## Usage
  66. See the [PostCSS documentation](https://github.com/postcss/postcss#usage) for
  67. examples for your environment.
  68. ## Contributors
  69. See [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).
  70. ## License
  71. MIT © [Ben Briggs](http://beneb.info)
  72. [postcss]: https://github.com/postcss/postcss