postcss-discard-comments

Discard comments in your CSS files with PostCSS.

MIT 61 个版本
安装
npm install postcss-discard-comments
yarn add postcss-discard-comments
pnpm add postcss-discard-comments
bun add postcss-discard-comments
README

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

版本列表
8.0.1 2026-06-11
8.0.0 2026-05-06
7.0.8 2026-05-02
7.0.7 2026-04-20
7.0.6 2026-03-06
7.0.5 2025-10-29
7.0.4 2025-05-06
7.0.3 2024-09-04
7.0.2 2024-08-09
7.0.1 2024-06-19
7.0.0 2024-04-24
6.0.2 2024-03-06
6.0.1 2023-12-14
6.0.0 2023-03-27
5.1.2 2022-05-29
5.1.1 2022-03-08
5.1.0 2022-03-01
5.0.3 2022-02-07
5.0.2 2022-01-23
5.0.1 2021-05-19
5.0.0-rc.2 2021-03-15
5.0.0-rc.1 2021-03-05
5.0.0-rc.0 2021-02-19
5.0.0-alpha.0 2021-02-19
5.0.0 2021-04-10
4.0.2 2019-02-12
4.0.1 2018-09-24
4.0.0-rc.2 2017-08-06
4.0.0-rc.0 2017-06-01
4.0.0 2018-07-04
2.0.4 2016-02-10
2.0.3 2015-12-26
2.0.2 2015-10-16
2.0.1 2015-10-08
2.0.0 2015-09-04
1.2.1 2015-08-13
1.2.0 2015-06-09
1.1.3 2015-06-09
1.1.2 2015-05-03
1.1.1 2015-04-08
1.1.0 2015-04-02
1.0.2 2015-03-25
1.0.1 2015-03-18
1.0.0 2015-03-18