4

How can I use CSS-Purge to clean up my code, without losing my comments and all formatting in my css file?

Thanks :)

KittMedia
  • 7,368
  • 13
  • 34
  • 38
  • 1
    Comments and whitespace take up filesize... why would you want to keep them when you're trying to make the filesize as small as possible? The whole **point** of minification is to make it as small as possible, **without** worrying about the readability of the minified file (you'll still have the comments in the source file). – Obsidian Age May 17 '18 at 04:20
  • I can't speak for James Pyle NewYears1978, but in my case, I'd want to do that with the intention of cleaning up/replacing the original source file (imagine it is a real mess). Removing all comments and formatting would make it unreadable. Minifying would come at a later stage. – TryHarder Jun 19 '18 at 13:56

1 Answers1

1

you can use the config options to turn on/off features.

In your scenario, you could set the following options to false:

  • trim_keep_non_standard_inline_comments
  • trim_removed_rules_previous_comment
  • trim_comments
  • trim_whitespace
  • trim_breaklines
  • trim_last_semicolon

or just set trim to false for all of them to be disabled.

If you're doing the global or local usage, you can pass in a config file with the -f command line option:

css-purge -f myconfig.json -i mycss.css -o mynewcss.css

If you're using it as a library, then you can just pass it in as a parameter:

var cssPurge = require('css-purge');

//purging a CSS string with options
var css = "p { color: blue; color: blue; } ";

cssPurge.purgeCSS(css, {
    trim : false,
    shorten : true
}, function(error, result){
    if (error)
        console.log(error)
    else
        console.log('Output CSS: ',  result);
});

Check out all the options at: http://rbtech.github.io/css-purge

There's an example config file structure in the Getting Started > Config section.

AEQ
  • 1,339
  • 1
  • 16
  • 20