Skip to content
This repository has been archived by the owner. It is now read-only.
DEPRECATED, see https://github.com/cssnano/cssnano | Discard comments in your CSS files with PostCSS.
JavaScript
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.all-contributorsrc
.babelrc
.editorconfig
.gitignore Tidy up. Feb 10, 2016
.travis.yml Update to ESLint 3. Jul 6, 2016
CHANGELOG.md
LICENSE-MIT Fixes for plugin guidelines. Jun 9, 2015
README.md Add all-contributors. Jun 25, 2016
package.json chore(package): update ava to version 0.17.0 Nov 24, 2016

README.md

postcss-discard-comments Build Status NPM version Dependency Status

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

Thanks goes to these wonderful people (emoji key):


Ben Briggs

💻 📖 👀 ⚠️

Dmitry Kiselyov

🐛 💻 📖 ⚠️

Ivan Vlasenko

💻

Joren Van Hee

🐛

André König

🐛

This project follows the all-contributors specification. Contributions of any kind welcome!

License

MIT © Ben Briggs

You can’t perform that action at this time.