家好,很高兴又见面了,我是"高级前端进阶",由我带着大家一起关注前端前沿、深入前端底层技术,大家一起进步,也欢迎大家关注、点赞、收藏、转发,您的支持是我不断创作的动力。
UnCSS 是一个从样式表中删除未使用的 CSS 的工具,可以跨多个文件工作,并支持 Javascript 注入的 CSS。
UnCSS 删除未使用规则的过程如下:
但是使用 Uncss 需要注意以下几点:
目前 uncss 在 Github 上通过 MIT 协议开源,有超过 9.3k 的 star,194k 的项目依赖量,是一个值得关注的前端开源项目。
下面是在 Node.js 环境中使用 uncss 的示例:
var uncss = require('uncss');
var files = ['my', 'array', 'of', 'HTML', 'files', 'or', 'http://urls.com'],
options = {
banner: false,
csspath: '../public/css/',
htmlroot: 'public',
ignore: ['#added_at_runtime', /test\-[0-9]+/],
ignoreSheets: [/fonts.googleapis/],
inject: function (window) {
window.document
.querySelector('html')
.classList.add('no-csscalc', 'csscalc');
},
jsdom: {
userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X)',
},
media: ['(min-width: 700px) handheld and (orientation: landscape)'],
raw: 'h1 { color: green }',
report: false,
strictSSL: true,
stylesheets: [
'lib/bootstrap/dist/css/bootstrap.css',
'src/public/css/main.css',
],
timeout: 1000,
uncssrc: '.uncssrc',
userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X)',
};
uncss(files, options, function (error, output) {
console.log(output);
});
/* Look Ma, no options! */
uncss(files, function (error, output) {
console.log(output);
});
/* Specifying raw HTML */
var rawHtml = '...';
uncss(rawHtml, options, function (error, output) {
console.log(output);
});
值得一提的是,UnCSS 还可以与其他 JavaScript 构建系统结合使用,例如: Grunt、Broccoli 或 Gulp,只需要安装特定的库即可。
在 CLI 环境中使用命令如下:
Usage: uncss [options] <file or URL, ...>
e.g. uncss https://getbootstrap.com/docs/3.3/examples/jumbotron/ > stylesheet.css
Options:
-h, --help output usage information
-V, --version output the version number
-i, --ignore <selector, ...> Do not remove given selectors
-m, --media <media_query, ...> Process additional media queries
-C, --csspath <path> Relative path where the CSS files are located
-s, --stylesheets <file, ...> Specify additional stylesheets to process
-S, --ignoreSheets <selector, ...> Do not include specified stylesheets
-r, --raw <string> Pass in a raw string of CSS
-t, --timeout <milliseconds> Wait for JS evaluation
-H, --htmlroot <folder> Absolute paths' root location
-u, --uncssrc <file> Load these options from <file>
-n, --noBanner Disable banner
-a, --userAgent <string> Use a custom user agent string
-I, --inject <file> Path to javascript file to be executed before uncss runs
-o, --output <file> Path to write resulting CSS to
请注意,可以将本地文件路径(由 glob 处理)和 URL 传递给程序。
/* uncss:ignore */
.selector1 {
/* this rule will be ignored */
}
.selector2 {
/* this will NOT be ignored */
}
/* uncss:ignore start */
/* all rules in here will be ignored */
/* uncss:ignore end */
https://github.com/uncss/uncss
https://m.youtube.com/watch?v=DX7McYRGJ8o
https://uncss-online.com/
powercfg -h off
前我写过一篇有关Windows10系统某个硬盘分区下名为“FileHistory”的文件夹能否删除的文章,有小伙伴表示疑问,你说删就删,删完了系统不稳定怎么办?你倒是说说这个文件夹是干啥用的啊!
答案很简单:这个文件夹对应着Windows 10系统的一类备份功能。具体开启、关闭可以按照如下步骤操作:首先打开Windows设置,选择“更新与安全”,再在左侧菜单栏中选择“备份”,就可以看到如下图所示的“使用文件历史记录进行备份”功能的开关了。
当然,既然你的某个盘符下已经出现过FileHistory文件夹,那么你之前一定打开过这个开关,或者现在就已经是开启状态。这个时候,你可以选择直接关闭它,再去删掉整个FileHistory文件夹。你也可以选择不关闭这个功能,而是打开FileHistory文件夹,将里面的文件有选择地清空。
由于我有冷备份的习惯,Windows 10自带的文件备份功能对我来说可有可无,只能算是一个附加的备份方案。硬盘空间够用的时候,我会留着它,多一个应急处理方案也挺好。不过,一旦硬盘空间吃紧,我会首先选择干掉这个文件夹里的文件。一般我每隔一两个月就清理一下。上一次清理到今天,已经有4个月了,该文件夹里的数据容量占用已经超过了660GB,我的3TB硬盘再次飙红!于是快刀斩乱麻,把里面的文件直接清空。
可能里面的文件太繁杂了,删除这个SSD硬盘上的600GB文件备份居然要用20分钟,不如删除一个几百GB的视频文件痛快。不过这不算麻烦,你可以去干别的,等十几分钟之后 ,少则几十GB、多则近千GB的占用空间就会被从硬盘中释放出来,可以极大地缓解硬盘容量将满的窘境。
上次科普时,我还和大家提到过,如果你点击备份开关下面一行的“备份选项”,还可以有针对性地只备份某几个对你更为重要的文件夹,这样就不至于让备份夹FileHistory短时间内变得臃肿不堪,造成硬盘负担。
如果你的硬盘空间实在有限,那么直接关闭这个备份功能也完全不会影响到系统运行,请放心关闭,不必担心少了这个功能。毕竟我们还有许多好用的第三方软件可以取代它,而且,更值得采用的备份/同步方案则是入手或DIY一台专门做这个的NAS设备,相信许多朋友早已活学活用,这里就不再赘述了。
我是笔点酷玩 ,关注我玩数码不迷路!
*请认真填写需求信息,我们会在24小时内与您取得联系。