扫一扫分享
Uncss 是一个用于移除脚本中无用 CSS 的工具。它可以审查多个文件,也可以审查由 JavaScript 注入的 CSS。
uncss安装
npm install -g uncss在node中使用:
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,
        banner       : false,
        uncssrc      : '.uncssrc',
        userAgent    : 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X)',
        inject       : function(window){ window.document.querySelector('html').classList.add('no-csscalc', 'csscalc'); }
    };
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);
}); 
仅供个人学习参考/导航指引使用,具体请以第三方网站说明为准,本站不提供任何专业建议。如果地址失效或描述有误,请联系站长反馈~感谢您的理解与支持!
手机预览
