Last active
July 20, 2019 00:22
-
-
Save sebnitu/3c7da627a75a890a9ba1fa0fa3034c3f to your computer and use it in GitHub Desktop.
An example file for creating multi-site build scripts using Gulp
This file contains 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
// Require Packages | |
var gulp = require('gulp'); | |
// Paths variable | |
var paths = { | |
themes: 'wp-content/themes/', | |
shared: 'shared/', | |
src: 'src/', | |
dest: 'dist/' | |
}; | |
// Themes variable | |
var themes = [{ | |
id : 'astra' | |
}, { | |
id : 'bistro' | |
}, { | |
id : 'cell' | |
}, { | |
id : 'nova' | |
}, { | |
id : 'quest' | |
}]; | |
// Tasks object | |
var tasks = { | |
'css' : [], | |
'js' : [], | |
'img' : [] | |
}; | |
// Loop through theme objects | |
themes.forEach(function (theme, index) { | |
// Construct our unique source and destination paths | |
var src = paths.themes + theme.id + '/' + paths.src; | |
var dest = paths.themes + theme.id + '/' + paths.dest; | |
// Save our tasks for later | |
tasks.css.push(theme.id + ':css'); | |
tasks.js.push(theme.id + ':js'); | |
tasks.img.push(theme.id + ':img'); | |
// CSS task | |
gulp.task(theme.id + ':css', function() { | |
// Our task code goes here... | |
}); | |
// JavaScript task | |
gulp.task(theme.id + ':js', function() { | |
// Our task code goes here... | |
}); | |
// Image processing task | |
gulp.task(theme.id + ':img', function() { | |
// Our task code goes here... | |
}); | |
// Watch task | |
gulp.task(theme.id + ':watch', function() { | |
gulp.watch(src + 'scss/**/*', [theme.id + ':css']); | |
gulp.watch(src + 'js/**/*', [theme.id + ':js']); | |
gulp.watch(src + 'img/**/*', [theme.id + ':img']); | |
}); | |
// Creates the :go tasks to run everything | |
gulp.task(theme.id + ':go', [ | |
theme.id + ':css', | |
theme.id + ':js', | |
theme.id + ':img' | |
]); | |
// Creates default task | |
gulp.task(theme.id, [ | |
theme.id + ':go', | |
theme.id + ':watch' | |
]); | |
}); | |
// Global CSS task | |
gulp.task('css', tasks.css); | |
// Global JavaScript task | |
gulp.task('js', tasks.js); | |
// Global image processing task | |
gulp.task('img', tasks.img); | |
// Global watch task | |
gulp.task('watch', function() { | |
// Loop through theme objects | |
themes.forEach(function (theme, index) { | |
// Construct our unique source path | |
var src = paths.themes + theme.id + '/' + paths.src; | |
// Theme specific watch tasks | |
gulp.watch(src + 'css/**/*', [theme.id + ':css']); | |
gulp.watch(src + 'js/**/*', [theme.id + ':js']); | |
gulp.watch(src + 'img/**/*', [theme.id + ':img']); | |
}); | |
// Shared watch tasks | |
gulp.watch(paths.shared + 'scss/**/*', ['css']); | |
gulp.watch(paths.shared + 'js/**/*', ['js']); | |
gulp.watch(paths.shared + 'img/**/*', ['img']); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment