Skip to content

Instantly share code, notes, and snippets.

@darkliquid
Created May 6, 2014 11:55
Show Gist options
  • Save darkliquid/7483b831dc701c335cde to your computer and use it in GitHub Desktop.
Save darkliquid/7483b831dc701c335cde to your computer and use it in GitHub Desktop.
// Handles js, sass, image optimisation/compilation and does very basic PHP linting and livereload
var gulp = require('gulp'),
minifycss = require('gulp-minify-css'),
notify = require('gulp-notify'),
cache = require('gulp-cache'),
sass = require('gulp-sass'),
uglify = require('gulp-uglify'),
gutil = require('gulp-util'),
refresh = require('gulp-livereload'),
lr = require('tiny-lr'),
rename = require('gulp-rename'),
exec = require('gulp-exec'),
include = require('gulp-include'),
server = lr();
gulp.task('sass', function(){
return gulp.src('sass/*.scss')
.pipe(sass())
.pipe(gulp.dest('public/css'))
.pipe(rename({ suffix: '.min' }))
.pipe(minifycss())
.pipe(gulp.dest('public/css'))
.pipe(refresh(server))
.pipe(notify({ message: "Sass compiled" }))
.on('error', gutil.log);
});
gulp.task('images', function() {
return gulp.src('images/**/*')
.pipe(cache(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true })))
.pipe(gulp.dest('public/images'))
.pipe(notify({ message: 'Images optimised' }))
.on('error', gutil.log);
});
gulp.task('js', function(){
return gulp.src('js/app.js')
.pipe(include())
.pipe(gulp.dest('public/js'))
.pipe(uglify())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('public/js'))
.pipe(refresh(server))
.pipe(notify({ message: 'Javascript compiled' }))
.on('error', gutil.log);
})
gulp.task('php', function(){
return gulp.src('public/*.php')
.pipe(exec('php -l <% file.path %>'))
.pipe(refresh(server))
.on('error', gutil.log);
})
gulp.task('livereload', function(){
return server.listen(35729, function(err){
if(err) return console.log(err);
});
});
gulp.task('default', ['livereload', 'sass'], function(){
gulp.watch('sass/**', ['sass']);
gulp.watch('js/**', ['js']);
gulp.watch('public/*.php', ['php']);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment