问题
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