什么是gulp任务异步完成

时间:2019-05-28 01:09:26

标签: gulp gulp-spritesmith

操作精灵时发生以下错误,您是否忘记了异步完成信号?

难以解决问题,因为我不擅长英语阅读,我需要帮助。我是韩国人T ^ T

var gulp = require('gulp'),
    spritesmith = require('gulp.spritesmith'),
    buffer = require('vinyl-buffer'),
    path = require('path'),
    fs = require('file-system'),

var src = 'src',
    Path = {
    sprite: src + '/img/sprite;
}

function getFolders(dir){
    return fs.readdirSync(dir)
        .filter(function(file){
        return fs.statSync(path.join(dir, file)).isDirectory();
    });
}

gulp.task('sprite', function () {
    var folders = getFolders(Path.sprite);
    folders.map(function(folder) {
        var spriteData = gulp.src(folder+'/*.png').pipe(spritesmith({
            imgName: folder+'_sprite.png',
            cssName: folder + '_sprite.scss',
            padding: 10,
            algorithm: 'binary-tree',
            cssVarMap: function(sprite) {
                sprite.name = folder + '-' + sprite.name;
                sprite.origin = 'sp_' + folder;
            },
            cssSpritesheetName: 'sp_' + folder
        }));

        spriteData.img
        .pipe(buffer())
        .pipe(gulp.dest(Path.sprite));
        spriteData.css.pipe(gulp.dest('src/scss/lib'));
    });
});

[10:03:33] The following tasks did not complete: sprite
[10:03:33] Did you forget to signal async completion?

0 个答案:

没有答案