Answer the question
In order to leave comments, you need to log in
How to run several identical tasks with different parameters using Gulp?
For example, a project has several themes that share common .sass files. When changing the shared file, you need to rebuild all the CSS of the theme (I use gulp-sass).
There is a build task and I can build each theme separately with a parameter (using yargs)
gulp build --theme theme1
gulp build --theme theme2
gulp build --theme theme3
...
Answer the question
In order to leave comments, you need to log in
You can try using promises. Bottom line: there is a build task, which works in essence the same as it worked for you before, but at the same time, the build: themes task was added, which takes an array of topics (here either set manually or parse the themes folder and get a list of paths) and after the build all topics, you can already display debugging information.
function build(theme) {
return new Promise(function(resolve) {
gulp.src([theme])
...
resolve();
});
}
var themeList = []; // Список стилей
gulp.task('build:themes', function() {
return Promise.all(themeList.map(function(theme) {
return build(theme);
})).then(function() {
// Отработает после того, как завершится сборка всех стилей
});
});
gulp.task('build', function() {
var theme = 'src/styles/' + (util.env.theme ? util.env.theme : 'main') + '.scss';
build(theme);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question