Skip to content

Instantly share code, notes, and snippets.

@gpbeer
Last active March 20, 2017 16:08
Show Gist options
  • Save gpbeer/3fb9801c9347b86a3f566ca63a64c749 to your computer and use it in GitHub Desktop.
Save gpbeer/3fb9801c9347b86a3f566ca63a64c749 to your computer and use it in GitHub Desktop.
Gulpfile sass task with multiple themes or directories using merge streams
var gulp = require('gulp');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var plumber = require('gulp-plumber');
var merge = require('merge-stream');
var util = require("gulp-util");
/*************************************
/* Paths to themes (Or './wp-content/themes/')
/*************************************/
var themes = {
root :'./web/app/themes/'
};
/*************************************
/* Paths of sources
/*************************************/
var source = {
folders : [
themes.root+'my-first-theme',
themes.root+'my-second-theme',
themes.root+'my-third-theme'
],
fileType : {
scss: '**/*.scss'
}
};
/*************************************
/* Task Sass
/*************************************/
gulp.task('sass', function () {
var tasks = source.folders.map(function(element){
// Console source folders
util.log(util.colors.green('Themes: '),util.colors.yellow( element ));
return gulp.src([
element + '/assets/scss/style.scss',
element + '/assets/scss/admin/dashboard.scss'
])
.pipe(plumber({
handleError: function (err) {
console.log(err);
this.emit('end');
}
}))
.pipe(sourcemaps.init())
.pipe(sass({debugInfo: true, errLogToConsole: true}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(element + '/css/'));
});
return merge(tasks);
});
/*************************************
/* Gulp Watch
/*************************************/
gulp.task('watch', ['sass'], function () {
gulp.watch( [source.fileType.scss], ['sass']).on('change', function(file) {
util.log(util.colors.yellow('SCSS changed' + ' (' + file.path + ')'));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment