DropCSS
DropCSS 介绍
Dropcss 是一个用来清理无用 css 的小工具,它根据 html 和 css 作为输入并返回那些有用到的 css 信息。 Dropcss删除所有未使用的样式块、重复的选择器、@keyframes等等。高度优化,速度极快。
Dropcss安装
npm install -D dropcss
Dropcss使用方法:
const dropcss = require('dropcss');
let html = `
<html>
<head></head>
<body>
<p>Hello World!</p>
</body>
</html>
`;
let css = `
.card {
padding: 8px;
}
p:hover a:first-child {
color: red;
}
`;
const whitelist = /#foo|.bar/;
let dropped = new Set();
let cleaned = dropcss({
html,
css,
shouldDrop: (sel) => {
if (whitelist.test(sel))
return false;
else {
dropped.add(sel);
return true;
}
},
});
console.log(cleaned.css);
console.log(dropped);
GitHub:https://github.com/leeoniya/dropcss
网站描述:一个用来清理无用 CSS 的小工具