在编译之前,将Lint SASS放在Gulp中

在编译之前,将Lint SASS放在Gulp中,sass,gulp,lint,Sass,Gulp,Lint,我是Gulp的新手,我正在尝试在编译scss文件之前将其过滤掉,以避免Gulp watcher崩溃 我的gulpfile.js现在看起来像这样: gulp.task('default', ['watch']); // Sass compilation to css gulp.task('build-css', function() { return gulp.src('source/scss/**/*.scss') .pipe(sourcemaps.init()) // Proce

我是Gulp的新手,我正在尝试在编译scss文件之前将其过滤掉,以避免Gulp watcher崩溃

我的
gulpfile.js
现在看起来像这样:

gulp.task('default', ['watch']);

// Sass compilation to css
gulp.task('build-css', function() {
  return gulp.src('source/scss/**/*.scss')
    .pipe(sourcemaps.init()) // Process the original sources
    .pipe(sass())
    .pipe(sourcemaps.write()) // Add the map to modified source.
    .pipe(gulp.dest('public/assets/css'));
});

// Configure which files to watch and what tasks to use on file changes
gulp.task('watch', function() {
  gulp.watch('source/scss/**/*.scss', ['build-css']);
});
当我在scss文件中输入错误时,如:

body {
    color: $non-existing-var;
}

gulp watcher显示错误信息,但停止监视,因为gulp中断了执行。如何解决这个问题?

我假设您正在使用,如果您没有使用,我建议您这样做。它是一个包装器,它是C版本:super-fast:)

在文档中,他们已经向您介绍了,因此您的任务应该如下所示:

gulp.task('build-css', function() {
  return gulp.src('source/scss/**/*.scss')
    .pipe(sourcemaps.init()) // Process the original sources
    .pipe(sass().on('error', sass.logError))
    .pipe(sourcemaps.write()) // Add the map to modified source.
    .pipe(gulp.dest('public/assets/css'));
});
希望这能帮助你完成你想要的:)