删除css中不使用的类

Remove unused classes in css

本文关键字:css 删除      更新时间:2023-09-26

我需要找到并删除页面上未使用的类(在html中未使用,但在css中存在)。我试图使用这个解决方案,但它说所有的类在我的网站上使用html。我的css被分成了几个文件

我想你可以在这里使用这个unss -> https://www.npmjs.com/package/uncss,像这样:

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'
    };