【问题标题】:Gulp streamqueue sass plumber watch. Errors breaks taskGulp streamqueue sass 管道工手表。错误中断任务
【发布时间】:2016-08-08 16:11:31
【问题描述】:

使用 Streamqueue、sass、plumber 的 gulp 任务出现问题并在最后观察它。 任务正在用我自己的供应商 css|scss 文件编译生产 css 文件。

gulp.task('fincss', function () {
    watch([workData.sassSrcFiles, workData.cssVendorSrcFiles], {}, function () {
        var convertFromScssToCssAndConcat =
            gulp.src(workData.sassSrcFiles)
                .pipe(plumber(error))
                .pipe(sass());

        var minifyAndConcatExistingCss =
            gulp.src(workData.cssVendorSrcFiles)
                .pipe(plumber(error));

        return sq({objectMode: true}, minifyAndConcatExistingCss, convertFromScssToCssAndConcat)
            .pipe(concat('final.min.css'))
            .pipe(uglifycss())
            .pipe(gulp.dest(workData.cssDest))
            .pipe(livereload());
    });
});

var error = function (e) {
    console.error('Error in plugin "' + e.plugin + '"');
    console.error('   "' + e.message + '"');
    console.error('   In file "' + e.fileName + '", line "' + e.lineNumber + '".');
    console.log('--------------------------------------');
    console.log(e);
};

但是当 scss 文件中的错误然后中断任务。无论如何,互联网上提供的任何管道工实验都对我没有帮助。在concat 之前插入plumber() 或在错误处理程序中使用this.emit('end') 之类的东西什么都不做。

在我的其他任务中,例如

gulp.task('toHtml', function () {
    watch(workData.pugSrcFiles, {}, function (e) {
        message('Start generating template.');
        gulp.src([workData.pugSrcFiles, '!' + workData.pugSrc + '_*.pug'])
            .pipe(plumber(error))
            .pipe(pug({pretty: true}))
            .pipe(gulp.dest(pubDir))
            .pipe(livereload());
    });
});

一切都很好,没有破坏任务。

请帮忙。

【问题讨论】:

    标签: stream gulp gulp-watch gulp-sass plumber


    【解决方案1】:

    你可以使用stream-series来代替streamqueue。

    将您的配置文件更改为:

    var series = require('stream-series');
    
    gulp.task('fincss', function () {
        watch([workData.sassSrcFiles, workData.cssVendorSrcFiles], {}, function () {
            var convertFromScssToCssAndConcat =
                gulp.src(workData.sassSrcFiles)
                    .pipe(plumber({errorHandler: function(error) {
                         convertFromScssToCssAndConcat.emit('end')  // important
                     }}))
                    .pipe(sass());
    
            var minifyAndConcatExistingCss =
                gulp.src(workData.cssVendorSrcFiles)
                    .pipe(plumber(error));
    
            return series(minifyAndConcatExistingCss, convertFromScssToCssAndConcat)
                .pipe(concat('final.min.css'))
                .pipe(uglifycss())
                .pipe(gulp.dest(workData.cssDest))
                .pipe(livereload());
        });
    

    });

    【讨论】:

    • 嗨,@leon,谢谢,但我收到错误 \node_modules\stream-series\index.js:23 e.pipe(pauseStream); TypeError: e.pipe is not a function at node_modules\stream-series\index.js:23:7 at Array.forEach (native) at module.exports node_modules\stream-series\index.js:20:11) at C:\projects\jp\gulpfile.js:83:16 at write (C:\projects\jp\node_modules\gulp-watch\index.js:144:3) at node_modules\gulp-watch\node_modules\vinyl-file\index.js:52:4 at node_modules\gulp-watch\node_modules\vinyl-file\node_modules\graceful-fs\graceful-fs.js:78:16 at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)
    • @PaulBurilichev,我无法从您在此处复制的错误日志中知道发生了什么。但是stream-series 应该可以工作。我在我的项目中使用过,可以参考github.com/njleonzhang/generator-gulp-ionic/blob/master/…的第118行
    • @PaulBurilicev,抱歉打错了,return series({objectMode: true}, minifyAndConcatExistingCss, convertFromScssToCssAndConcat) 应该是`return series(minifyAndConcatExistingCss, convertFromScssToCssAndConcat)`
    猜你喜欢
    • 2021-09-19
    • 1970-01-01
    • 2014-08-28
    • 2015-03-25
    • 2018-12-03
    • 2021-07-29
    • 1970-01-01
    • 1970-01-01
    • 2016-08-23
    相关资源
    最近更新 更多