gulp-sass not showing any errors

ε祈祈猫儿з 提交于 2019-12-24 13:08:05

问题


Sass with .sass files,

Here is my gulpfile,

var gulp = require('gulp'),
    sass = require('gulp-sass'),
    connect = require('gulp-connect');

connect.server({port: 8000, livereload: true});

function exceptionLog (error) {
  console.log(error.toString());
  this.emit('end');
}

gulp.task('sass', function () {
    gulp.src('sass/*.sass')
        .pipe(sass({
            outputStyle: 'expanded',
            }))
        .on('error', exceptionLog)
        .pipe(gulp.dest('css'))
        .on('error', exceptionLog)
        .pipe(sass.sync().on('error', sass.logError));
});

gulp.task('reload', function () {
    gulp.src('*.html')
        .pipe(connect.reload())
        .on('error', exceptionLog);
});

gulp.task('default', function() {
    gulp.watch(['*.html'],['reload']);
    gulp.watch('**/*.sass', ['sass','reload']);
});

This setup works well for .scss files, while now on this project, I have to stick with .sass, Gulp setup with this gulpfile does not breaks or display any errors (but compiles if no errors). but only the correct syntax will be compiled. while if change to .scss, it logs the errors.


回答1:


You need to attach the error event listener to the sass stream, not your gulp stream or later in the stream when the error has already been thrown. Also, use the built in logError function to log errors:

.pipe(sass().on('error', sass.logError))

Full example:

gulp.task('sass', function () {
  return  gulp.src('sass/*.sass')
    .pipe(sass({outputStyle: 'expanded'}).on('error', sass.logError))
    .pipe(gulp.dest('css'))
    .on('error', exceptionLog);
}


来源:https://stackoverflow.com/questions/33860135/gulp-sass-not-showing-any-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!