Run Gulp tasks with loop

百般思念 提交于 2019-12-01 09:43:17

I think an option here is to merge a series of gulp.src() streams and return the merged streams. Here is your code modified to use the merge-stream npm package (https://www.npmjs.com/package/merge-stream).

var mergeStream = require('merge-stream');

gulp.task('mustache', function () {
    console.log('Found ' + Object.keys(strings).length + ' languages.');
    var tasks = [];
    for (var l in strings) {
        var lang = strings[l];
        tasks.push(
            gulp.src(buildpath + '/index.html')
                .pipe(mustache(lang))
                .pipe(rename('index_' + l + '.html'))
                .pipe(compressor({
                    'remove-intertag-spaces': true,
                    'compress-js': true,
                    'compress-css': true
                }))
                .pipe(gulp.dest(destpath + '/'))
        );
    }
    return mergeStream(tasks);
});

You can try async

var async = require('async');

gulp.task('build', function (done) {
 var tasks = [];
    for (var i = 0; i < config.length; i++) {
        tasks.push(function () {
            var tmp = config[i];
            return function (callback) {
                gulp.src(tmp.src)
                  .pipe( blah blah blah
                  ))
                  .pipe(gulp.dest(tmp.dest))
                  .on("end", callback);
            }
        }());
    }
    async.parallel(tasks, done);
});
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!