Answer the question
In order to leave comments, you need to log in
Gulp's Task in a loop?
Please explain how to execute a task in a loop. Or is it possible to somehow debug the task with console.log.
Essence:
gulp.task('sprite', function() {
var pages = [
'index',
'about',
'members'
]
for (var i = 0; i < pages.length; i++){
var spriteData =
gulp.src('./img/sprite/before/'+pages[i]+'/') // путь, откуда берем картинки для спрайта
.pipe(console.log(pages[i]))
.pipe(spritesmith({
imgName: 'sprite_'+pages[i]+'.png',
cssName: 'sprite_'+pages[i]+'.styl',
cssFormat: 'stylus',
algorithm: 'binary-tree',
padding: 1,
cssTemplate: 'stylus.template.mustache',
cssVarMap: function(sprite) {
sprite.name = 's-' + sprite.name
}
}));
spriteData.img.pipe(gulp.dest('./img/sprite/')); // путь, куда сохраняем картинку
spriteData.css.pipe(gulp.dest('./stylus/')); // путь, куда сохраняем стили
console.log(gulp.src);
}
});
Answer the question
In order to leave comments, you need to log in
You have an error in your code.
You probably meant to refer to the length here, but at the same time you created an object and get an undefined field.
If you want to work with pages as an array, create it as an arrayvar pages = ['index', 'about', 'members'];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question