如何阻止gulp-csslint错误?

时间:2014-03-31 15:22:38

标签: gulp

我有示例代码:

var csslint = require('gulp-csslint');
gulp.task('csslint', function() {
    return gulp.src(paths.css)
        .pipe(csslint())
        .pipe(csslint.reporter());
});

有例如:

[gulp] Starting 'csslint'...
[gulp] 1 error found in /some/app.css
[gulp] [L37:C29] Unknown property 'align'. Properties should be known (listed in CSS3 specification) or be a vendor-prefixed property. (known-properties)
[gulp] Finished 'csslint' after 57 ms

和gulp继续做其他任务。 如何阻止gssp csslint错误?

3 个答案:

答案 0 :(得分:3)

要让gulp停止,再添加一个.pipe()调用,传入csslint.failReporter()

var csslint = require('gulp-csslint');
gulp.task('csslint', function() {
    return gulp.src(paths.css)
        .pipe(csslint())
        .pipe(csslint.reporter())
        .pipe(csslint.failReporter());
});

答案 1 :(得分:1)

我将水管工与gulpif插件结合使用 当我在手表模式下运行时,我会使用水管工,在其他情况下没有。

plumber = require('gulp-plumber'),
gulpif = require('gulp-if')

...
var cssTask = function (options) {
  var minifyCSS = require('gulp-minify-css'),
    less = require('gulp-less'),
    src = cssDependencies;

  src.push(codePath + '**/*.less');

  var run = function () {
    var start = Date.now();

    console.log('Start building CSS/LESS bundle');

    gulp.src(src)
      .pipe(gulpif(options.devBuild, plumber({
        errorHandler: onError
      })))
      .pipe(concat('main.css'))
      .pipe(less())
      .pipe(gulpif(options.minify, minifyCSS()))
      .pipe(gulp.dest(buildPath + 'css'))
      .pipe(gulpif(options.devBuild, browserSync.reload({stream:true})))
      .pipe(notify(function () {
        console.log('END CSS/LESS built in ' + (Date.now() - start) + 'ms');
      }));
  };

  run();

  if (options.watch) {
    gulp.watch(src, run);
  }
};

function onError (err) {
  console.log(err);
}

答案 2 :(得分:0)

我读了一些你使用gulp-plumber的地方。尝试一下。