angeli angeli - 1 year ago 207
Javascript Question

Remove unused classes in css

I need to find and delete unused classes on a page (unused in html but present in css). I tried to use this solution, but it said all classes are used in html on my site. My css is split into a few files.

Answer Source

I think you can use this uncss here -> like this:

var uncss = require('uncss');

var files   = ['my', 'array', 'of', 'HTML', 'files', 'or', ''],
    options = {
        ignore       : ['#added_at_runtime', /test\-[0-9]+/],
        media        : ['(min-width: 700px) handheld and (orientation: landscape)'],
        csspath      : '../public/css/',
        raw          : 'h1 { color: green }',
        stylesheets  : ['lib/bootstrap/dist/css/bootstrap.css', 'src/public/css/main.css'],
        ignoreSheets : [/fonts.googleapis/],
        timeout      : 1000,
        htmlroot     : 'public',
        report       : false,
        uncssrc      : '.uncssrc'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download