Created
May 9, 2014 10:08
-
-
Save larswittenberg/6067a241e02b8cfcaf2d to your computer and use it in GitHub Desktop.
Gulpfile
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'); | |
var sass = require('gulp-sass'); | |
var minifycss = require('gulp-minify-css'); | |
var rename = require('gulp-rename'); | |
var jshint = require('gulp-jshint'); | |
var concat = require('gulp-concat'); | |
var uglify = require('gulp-uglify'); | |
var notify = require('gulp-notify'); | |
var browserSync = require('browser-sync'); | |
/******************************************************************************* | |
* NOTIFY TASKS | |
*******************************************************************************/ | |
function scssError(error){ | |
return "\n"+error.message+"\n"; | |
} | |
function jshintErrors(file){ | |
if(file.jshint.success){ | |
return false; | |
} | |
// get jshint errors and count them | |
var errorCount = 0; | |
var errors = file.jshint.results.map(function(data){ | |
if(data.error){ | |
errorCount++; | |
return '(Line '+data.error.line+': Column '+data.error.character+') ' + data.error.reason; | |
} | |
}).join("\n"); | |
if(errorCount===0) return false; | |
return "\n"+ file.relative +' ('+ errorCount +' error'+(errorCount!==1?'s':'')+'):'+"\n" + errors + "\n"; | |
} | |
/******************************************************************************* | |
* Lint TASK | |
*******************************************************************************/ | |
gulp.task('lint', function () { | |
gulp.src('js/javascript.js') | |
.pipe(jshint()) | |
.pipe(jshint.reporter('default')) | |
.pipe(notify(jshintErrors)); | |
}); | |
/******************************************************************************* | |
* SASS TASK | |
*******************************************************************************/ | |
gulp.task('sass', function () { | |
gulp.src('sass/styles.scss') | |
.pipe(sass({ | |
includePaths: ['scss'], | |
sourceComments: 'map' | |
}).on('error', notify.onError(scssError))) | |
.pipe(gulp.dest('css')) | |
.pipe(rename('styles.min.css')) | |
.pipe(minifycss()) | |
.pipe(gulp.dest('css')); | |
}); | |
/******************************************************************************* | |
* JavaScript TASK | |
*******************************************************************************/ | |
gulp.task('js', function () { | |
gulp.src(['js/source/**/*.js', 'js/javascript.js']) | |
.pipe(concat('javascript.min.js')) | |
.pipe(uglify()) | |
.pipe(gulp.dest('js')); | |
}); | |
/******************************************************************************* | |
* BROWSERSYNC TASK | |
*******************************************************************************/ | |
gulp.task('browser-sync', function() { | |
browserSync.init(["css/*.css", "js/*.js", "application/views/**/*.tpl"]); | |
}); | |
/******************************************************************************* | |
* GULP WATCH | |
*******************************************************************************/ | |
gulp.task('watch', function () { | |
gulp.watch("sass/**/*.scss", ['sass']); | |
gulp.watch("js/**/*.js", ['lint', 'js']); | |
}); | |
/******************************************************************************* | |
* GULP DEFAULT TASK | |
*******************************************************************************/ | |
gulp.task('default', ['lint', 'sass', 'js', 'browser-sync', 'watch']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment