DropCSS是一个用来清理无用CSS的小工具,它根据HTML和CSS作为输入并返回那些有用到的CSS信息。
使用方法:
costdropcss=require('dropcss');lethtml=`<html><head></head><body><p>HelloWorld!</p></body></html>`;letcss=`.card{paddig:8px;}p:hovera:first-child{color:red;}`;costwhitelist=/#foo|\.bar/;letdropped=ewSet();//returs{css}letcleaed=dropcss({html,css,shouldDrop:(sel)=>{if(whitelist.test(sel))returfalse;else{dropped.add(sel);returtrue;}},});cosole.log(cleaed.css);cosole.log(dropped);










评论