Jul 30, 2017 · 1 min read
Thank you for the nice intro to Gulp. Is there a way to DRY out these 3 tasks? They are very similar.
// copy all HTML files from src to tmp
gulp.task(‘html’, function() {
return gulp.src(paths.srcHTML)
.pipe(gulp.dest(paths.tmp));
});// copy all CSS files from src to tmp
gulp.task(‘css’, function() {
return gulp.src(paths.srcCSS)
.pipe(gulp.dest(paths.tmp));
});// copy all JS files from src to tmp
gulp.task(‘js’, function() {
return gulp.src(paths.srcJS)
.pipe(gulp.dest(paths.tmp));
});
There must be a way to make a single function that can be reused for each filetype. Something like the code below, but I cant quite figure it out.
gulp.task('html', genericCopy(HTML));
gulp.task('css', genericCopy(CSS));
gulp.task('js', genericCopy(JS));genericCopy(string) => {
return gulp.src(paths.("src" + string))
.pipe(gulp.dest(paths.tmp));
}
