我需要查找并删除页面上未使用的类(未在 html 中使用但存在于 css 中)。我尝试使用 this解决方案,但它说我网站上的所有类都用在 html 中。我的 css 被分成几个文件。
最佳答案
我想你可以在这里使用这个 uncss -> 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'
};
关于javascript - 删除 css 中未使用的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40555766/