Skip to content

Instantly share code, notes, and snippets.

@nmaxcom
Created November 1, 2018 14:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmaxcom/6b88c262efb53d62c0e3801c5c25cbff to your computer and use it in GitHub Desktop.
Save nmaxcom/6b88c262efb53d62c0e3801c5c25cbff to your computer and use it in GitHub Desktop.
How to make a Gulpfile use different inputs and outputs keeping DRY?
/*
This is the barebones proof of concept:
*/
const gulp = require('gulp');
const p = {
dashboard: {
orig: ['public/dashboard/scss/style.scss', 'public/dashboard/styles/*.css'],
dest: 'public/dashboard/css/',
},
public: {
orig: ['public/styles/custom.scss', 'public/styles/*.css'],
dest: 'public/css/',
},
};
gulp.task('default', function() {
Object.keys(p).forEach(val => { // <--- The important bit! 'val' will go once as 'dashboard' and once as 'public'
return gulp
.src(p[val].css.orig)
/*
add here all your usual
'middleware' such as:
.pipe(sass())
.pipe(concat('main.css'))
.pipe(cleanCss())
etc.
*/
.pipe(gulp.dest(p[val].css.dest))
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment