Gulp Sass with errLogToConsole: true still stopping my other watch tasks

ⅰ亾dé卋堺 提交于 2019-11-28 05:33:41

问题


I currently have 3 watch tasks as so:

gulp.task('watch', function(){
    gulp.watch(sassDir + '/*.scss', ['sass']);
    gulp.watch(cssDir + '/*.css', ['css']);
    gulp.watch(jsDir + '/*.js', ['js']);
})

My issue right now is that when Sass throws an error all watch tasks stops. I then added .pipe(sass({errLogToConsole: true})) - which seems to keep my sass watch task alive even with an error, however the two other watch tasks doesnt seem to run.

How do I keep all of my watch tasks a live, so that an error in my sass file doesn't stop everything from being compiled?

My setup:

gulp.task('sass', function () {
    gulp.src(sassDir + '/**/*.scss')
        .pipe(sass({errLogToConsole: true}))
        .pipe(gulp.dest(sassTargetDir));
});

gulp.task('css', function() {
  gulp.src(cssDir + '/**/*.css')
    .pipe(autoprefix({
            browsers: ['last 40 versions'],
            cascade: false
        }))
    .pipe(gulp.dest(cssTargetDir))
    .pipe(minify())
    .pipe(rename({suffix: '.min'}))
    .pipe(gulp.dest(cssTargetDir));
});

gulp.task('js', function() {
  gulp.src(jsDir + '/**/*.js')
    .pipe(gulp.dest(jsTargetDir))
    .pipe(uglify())
    .pipe(rename({suffix: '.min'}))
    .pipe(gulp.dest(jsTargetDir))
});

gulp.task('watch', function(){
    gulp.watch(sassDir + '/*.scss', ['sass']);
    gulp.watch(cssDir + '/*.css', ['css']);
    gulp.watch(jsDir + '/*.js', ['js']);
})

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

回答1:


errLogToConsole is deprecated (or doesn't work) with Gulp 2.0+. Try using this in place of .pipe(sass({errLogToConsole: true})).

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

I use that with the watch command and the errors don't stop Gulp.

I got this from the Gulp sample code and a few more up-to-date Gulp guides. Check here in the future. https://github.com/dlmanning/gulp-sass



来源:https://stackoverflow.com/questions/29808095/gulp-sass-with-errlogtoconsole-true-still-stopping-my-other-watch-tasks

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