Last active
October 8, 2015 08:29
-
-
Save spicecadet/9b11a08d4f4dbc73aa4d to your computer and use it in GitHub Desktop.
This is an example gulp workflow that I run locally which handles sass compiling, image optimization, minification and reloading.
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
// gulp plugins | |
var gulp = require('gulp'); | |
var sass = require('gulp-sass'); | |
var autoprefixer = require('gulp-autoprefixer'); | |
var livereload = require('gulp-livereload'); | |
var concat = require('gulp-concat'); | |
var uglify = require('gulp-uglify'); | |
var minify = require('gulp-minify-css'); | |
var imageop = require('gulp-image-optimization'); | |
var livereload = require('gulp-livereload'); | |
// file paths | |
var style_in = './sass/**/*.scss'; | |
var style_out = './'; | |
var script_in = './js/*.js'; | |
var script_out = './dist/js'; | |
var images_in = './images/*.jpg'; | |
var images_out = './dist/images'; | |
var sassOptions = { | |
errLogToConsole: true, | |
outputStyle: 'expanded' | |
}; | |
gulp.task('sass', function (){ | |
return gulp | |
.src(style_in) | |
.pipe(sass(sassOptions).on('error', sass.logError)) | |
.pipe(autoprefixer('last 2 version')) | |
.pipe(concat('style.css')) | |
.pipe(minify({compatibility: 'ie8'})) | |
.pipe(gulp.dest(style_out)) | |
.pipe(livereload()); | |
}); | |
gulp.task('uglify', function(){ | |
return gulp | |
.src(script_in) | |
.pipe(uglify()) | |
.pipe(gulp.dest(script_out)); | |
}); | |
gulp.task('optimize', function(){ | |
gulp.src(images_in) | |
.pipe(imageop({ | |
optimizationLevel: 5, | |
progressive: true, | |
interlaced: true | |
})) | |
.pipe(gulp.dest(images_out)); | |
}); | |
gulp.task('watch', function(){ | |
livereload.listen(); | |
return gulp | |
.watch(style_in, ['sass']) | |
.on('change', function( event ){ | |
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...'); | |
livereload.changed; | |
}); | |
}); | |
gulp.task('default', ['sass', 'watch', 'optimize' ]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment