Created
November 1, 2018 14:18
-
-
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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