• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ben-eb/gulp-uncss: DEPRECATED. Remove unused CSS selectors.

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

ben-eb/gulp-uncss

开源软件地址(OpenSource Url):

https://github.com/ben-eb/gulp-uncss

开源编程语言(OpenSource Language):

JavaScript 100.0%

开源软件介绍(OpenSource Introduction):

Deprecation Notice

Since UnCSS is now a PostCSS plugin which can be combined with other CSS processing steps, there is little incentive to add a separate pass to your build step. Instead of using gulp-uncss, you can replicate the functionality by the following gulp task:

var gulp = require('gulp');
var postcss = require('gulp-postcss');
var uncss = require('postcss-uncss');

gulp.task('default', function () {
    var plugins = [
        uncss({
            html: ['index.html', 'posts/**/*.html', 'http://example.com']
        }),
    ];
    return gulp.src('./src/*.css')
        .pipe(postcss(plugins))
        .pipe(gulp.dest('./dest'));
});

Now you can add other plugins to complement UnCSS, such as cssnano.

gulp-uncss

Remove unused CSS with UnCSS.

If you have any difficulties with the output of this plugin, please use the UnCSS tracker.

Install

With npm do:

npm install gulp-uncss --save-dev

Example

Single files, globbing patterns and URLs are all supported by gulp-uncss, and can be mixed and matched:

var gulp = require('gulp');
var uncss = require('gulp-uncss');

gulp.task('default', function () {
    return gulp.src('site.css')
        .pipe(uncss({
            html: ['index.html', 'posts/**/*.html', 'http://example.com']
        }))
        .pipe(gulp.dest('./out'));
});

gulp-uncss can also be used in a pipeline that involves CSS pre-processing. Utilising many transforms on a single file is one of gulp's strengths:

var gulp = require('gulp');
var uncss = require('gulp-uncss');
var sass = require('gulp-sass');
var concat = require('gulp-concat');
var nano = require('gulp-cssnano');

gulp.task('default', function () {
    return gulp.src('styles/**/*.scss')
        .pipe(sass())
        .pipe(concat('main.css'))
        .pipe(uncss({
            html: ['index.html', 'posts/**/*.html', 'http://example.com']
        }))
        .pipe(nano())
        .pipe(gulp.dest('./out'));
});

In just a few lines, we compiled SCSS source into a single file, removed unused CSS and minified the output!

Options

Please see the UnCSS documentation for all of the options you can use. Some of them aren't as necessary when using gulp-uncss, because the CSS to analyse comes from the stream rather than the HTML files. The main options you will likely be using are:

html

Type: Array|String Required value.

An array which can contain an array of files relative to your gulpfile.js, and which can also contain URLs. Note that if you are to pass URLs here, then the task will take much longer to complete. If you want to pass some HTML directly into the task instead, you can specify it here as a string.

ignore

Type: Array Default value: undefined

Selectors that should be left untouched by UnCSS as it can't detect user interaction on a page (hover, click, focus, for example). Both literal names and regex patterns are recognized.

timeout

Type: Integer Default value: undefined

Specify how long to wait for the JS to be loaded.

Note that options.ignoreSheets is already defined for you. gulp-uncss will only process CSS files in the stream.

Contributing

Pull requests are welcome. If you add functionality, then please add unit tests to cover it.

License

MIT © Ben Briggs




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
dDenysS/gulp-template发布时间:2022-06-21
下一篇:
dbpoo/dbpoo.gulp: gulp发布时间:2022-06-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap