Last active
November 14, 2018 17:09
-
-
Save mikowl/6aa0da85cae20ed37008a81b4530daa6 to your computer and use it in GitHub Desktop.
Simple gulpfile for WP theme
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
/* ========================================================================== | |
Dependencies | |
========================================================================== */ | |
var gulp = require('gulp'), | |
clean = require('gulp-clean'), | |
uglify = require('gulp-uglify'), | |
autoprefixer = require('gulp-autoprefixer'), | |
concat = require('gulp-concat'), | |
rename = require('gulp-rename'), | |
sass = require('gulp-sass'), | |
notify = require("gulp-notify"), | |
cache = require('gulp-cache'), | |
imagemin = require('gulp-imagemin'), | |
plumber = require('gulp-plumber'); | |
/* ========================================================================== | |
Sources - Set your folders here | |
========================================================================== */ | |
var source = { | |
// Javascript folder | |
js_src: "./js", | |
// Javascript Library folder | |
js_libs: "./js/lib/", | |
// Sass folder | |
sass_src: "./sass", | |
//CSS output folder | |
css_src: "./" | |
}; | |
/* ========================================================================== | |
Sass watch task | |
Watches and compiles sass files in sass directory, also applies autoprefier | |
========================================================================== */ | |
gulp.task('sass', function(){ | |
// return gulp.src('./sass/*.scss') | |
return gulp.src(source.sass_src+'/*.scss') | |
.pipe(plumber({errorHandler: notify.onError("Ack. <%= error.message %>")})) | |
.pipe(sass({ | |
outputStyle: 'compressed', | |
noCache: true | |
}) | |
.on('error', sass.logError)) | |
.pipe(autoprefixer('last 100 versions')) | |
.pipe(gulp.dest(source.css_src)); | |
}); | |
/* ========================================================================== | |
gulp scripts | |
Concatenates and minifies javascript files excluding modernizr | |
and IE6-8 specific selectivizr.js | |
========================================================================== */ | |
// Your javascript vendor/library files to be concatenated and minified | |
gulp.task('scripts', ['cleanScripts'], function() { | |
return gulp.src([source.js_libs+'/*.js', '!'+source.js_libs+'modernizr.js', '!'+source.js_libs+'selectivizr.js']) | |
.pipe(concat("plugins.js")) | |
.pipe(gulp.dest(source.js_src)) | |
.pipe(rename({suffix: '.min'})) | |
.pipe(uglify()) | |
.pipe(gulp.dest(source.js_src)) | |
.pipe(notify({message: 'Scripts are done.'})); | |
}); | |
// Clean plugins.min.js file | |
gulp.task('cleanScripts', function() { | |
return gulp.src('./js/plugins.min.js', {read: false}) | |
.pipe(clean()); | |
}); | |
/* ========================================================================== | |
gulp images | |
Minifies images | |
========================================================================== */ | |
gulp.task('images', function() { | |
gulp.src('./images/**') | |
.pipe(cache(imagemin({ | |
optimizationLevel: 5, | |
progressive: true, | |
interlaced: true | |
}))) | |
.pipe(gulp.dest('./images/')) | |
.pipe(notify({ | |
message: "Images are optimized." | |
})); | |
}); | |
/* ========================================================================== | |
gulp watch | |
Main gulp task to watch sass files for changes | |
========================================================================== */ | |
gulp.task('watch', function () { | |
// Watch .scss files | |
gulp.watch(source.sass_src+'/**/*.scss', ['sass']); | |
// Watch all files for changes | |
gulp.watch(['./*', '!./*.css']); | |
}); | |
/* ========================================================================== | |
default task | |
========================================================================== */ | |
gulp.task('default', function(){ | |
gulp.start('watch', 'scripts', 'images'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment