angeli angeli - 28 days ago 5
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

I think you can use this uncss here -> https://www.npmjs.com/package/uncss like this:

var uncss = require('uncss');

var files   = ['my', 'array', 'of', 'HTML', 'files', 'or', 'http://urls.com'],
    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'
    };