Gulp task with different source depending on arguments
You were on the right track with your second try, just needed to utilize a bit of DRY and closures
function createTransformTaskClosure (destination) {
return function () {
return gulp.src(config.sourceJSX)
.pipe(gulp.dest(destination));
};
}
gulp.task('dev', createTransformTaskClosure(config.output_development));
gulp.task('prod', createTransformTaskClosure(config.output_production));
I did something similar using a single function:
function getDest(folder){
var folder = folder || '';
var newDest;
if (args.build){
newDest = config.build.home + folder;
}
if (args.temp){
newDest = config.temp.home + folder;
}
return newDest;
}
Then, when I'd call the gulp.dest():
.pipe(gulp.dest(getDest())) // defaults to ./ directory
Or if I wanted a subfolder:
.pipe(gulp.dest(getDest(config.css)))
My config file simply had paths, i.e.:
config = {
css: '/css/',
home: './',
js: '/js/'
}
Hope that helps.