Last active
August 29, 2015 14:05
-
-
Save iCodeForBananas/c6979d7bc415a0a6436b to your computer and use it in GitHub Desktop.
Gulpfile for working with wordpress or plain front end websites.
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 Modules | |
//=================================================================== | |
var gulp = require('gulp'), | |
plugins = require('gulp-load-plugins')({ camelize: true }); | |
var themeDir = "wp-content/themes/theme-name"; | |
// | |
// Styles | |
//=================================================================== | |
gulp.task('inline-styles', function() { | |
return gulp.src([ | |
themeDir + "/css/bootstrap.min.css", | |
themeDir + "/css/inline-styles.css" | |
]) | |
.pipe(plugins.concat('inline-styles.min.css')) | |
.pipe(plugins.autoprefixer(["last 2 versions", "> 1%", "ie 8"], { cascade: true })) | |
.pipe(plugins.minifyCss()) | |
.pipe(gulp.dest(themeDir + "/css")); | |
}); | |
gulp.task('async-styles', function() { | |
return gulp.src(themeDir + "/css/async-styles.css") | |
.pipe(plugins.autoprefixer(["last 2 versions", "> 1%", "ie 8"], { cascade: true })) | |
.pipe(plugins.rename("style.css")) | |
.pipe(plugins.minifyCss()) | |
.pipe(gulp.dest(themeDir)); | |
}); | |
// | |
// Scripts | |
//=================================================================== | |
gulp.task('scripts', function() { | |
return gulp.src([ | |
themeDir + "/js/bootstrap.min.js", | |
themeDir + "/js/scripts.js" | |
]) | |
.pipe(plugins.concat('scripts.min.js')) | |
.pipe(plugins.uglify()) | |
.pipe(gulp.dest(themeDir + "/js")); | |
}); | |
// | |
// Images | |
//=================================================================== | |
gulp.task('images', function() { | |
return gulp.src('images/**/*') | |
.pipe(plugins.cache(plugins.imagemin({ | |
optimizationLevel: 7, | |
progressive: true, | |
interlaced: true | |
}))) | |
.pipe(gulp.dest('images')); | |
}); | |
// | |
// Watch | |
//=================================================================== | |
gulp.task('watch', function () { | |
var server = plugins.livereload(); | |
var reloadServer = function(file) { | |
server.changed(file.path); | |
}; | |
// Star the livereload server | |
// You may need to refresh your browser to get it started | |
plugins.livereload.listen(); | |
gulp.watch(themeDir + '/css/inline-styles.css', ["inline-styles"]).on('change', reloadServer); | |
gulp.watch(themeDir + '/css/async-styles.css', ["async-styles"]).on('change', reloadServer); | |
gulp.watch(themeDir + '/js/**/scripts.js', ['scripts']).on('change', reloadServer); | |
gulp.watch('images/', ['images']).on('change', reloadServer); | |
gulp.watch([ | |
"wp-content/themes/theme-name/**/*.php", | |
"another-folder/**/*.php" | |
]).on('change', reloadServer); | |
}); | |
// | |
// Define Gulp Tasks | |
//=================================================================== | |
gulp.task('default', ['watch']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment