Gulp Sass with errLogToConsole: true 仍然停止我的其他监视任务 [英] Gulp Sass with errLogToConsole: true still stopping my other watch tasks

查看:17
本文介绍了Gulp Sass with errLogToConsole: true 仍然停止我的其他监视任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有 3 个监视任务:

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

我现在的问题是,当 Sass 抛出错误时,所有监视任务都会停止.然后我添加了 .pipe(sass({errLogToConsole: true})) - 这似乎使我的 sass watch 任务即使出现错误也能保持活动状态,但是其他两个 watch 任务似乎没有运行.p>

如何让我的所有监视任务保持实时状态,以便我的 sass 文件中的错误不会阻止所有内容的编译?

我的设置:

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(自动前缀({浏览器:['最近 40 个版本'],级联:假})).pipe(gulp.dest(cssTargetDir)).pipe(缩小()).pipe(重命名({suffix: '.min'})).pipe(gulp.dest(cssTargetDir));});gulp.task('js', function() {gulp.src(jsDir + '/**/*.js').pipe(gulp.dest(jsTargetDir)).pipe(丑化()).pipe(重命名({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']);

解决方案

errLogToConsole 在 Gulp 2.0+ 中被弃用(或不起作用).尝试使用它代替 .pipe(sass({errLogToConsole: true})).

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

我将它与 watch 命令一起使用,并且错误不会停止 Gulp.

我从 Gulp 示例代码和一些最新的 Gulp 指南中得到了这个.以后在这里检查.https://github.com/dlmanning/gulp-sass

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']);

解决方案

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

这篇关于Gulp Sass with errLogToConsole: true 仍然停止我的其他监视任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆