Joe Astuccio
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));
}
Joe Astuccio

Written by

Web Developer, Sailor, Stargazer, Hockey Player, and all around fun guy... but my absolute favorite thing is being a dad.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade