Created
April 26, 2015 20:03
-
-
Save kalepail/e18e7b4a75bd6aa870af to your computer and use it in GitHub Desktop.
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
var gulp = require('gulp'), | |
sass = require('gulp-sass'), | |
autoprefixer = require('gulp-autoprefixer'), | |
minifycss = require('gulp-minify-css'), | |
jshint = require('gulp-jshint'), | |
uglify = require('gulp-uglify'), | |
imagemin = require('gulp-imagemin'), | |
livereload = require('gulp-livereload'), | |
phpServer = require('php-built-in-server'), | |
scsslint = require('gulp-scsslint'), | |
newer = require('gulp-newer'), | |
globbing = require('gulp-css-globbing'), | |
cmq = require('gulp-combine-media-queries'); | |
// EXTRAS // --------------------------------------------------------- | |
// CSS linting | |
gulp.task('lint-css', function() { | |
return gulp.src(['dev/sass/**/*.scss', '!dev/sass/vendor/*.scss']) | |
.pipe(scsslint()) | |
.pipe(scsslint.reporter()); | |
}); | |
// JS linting | |
gulp.task('lint-js', function() { | |
return gulp.src(['dev/js/**/*.js', '!dev/js/vendor/*.js']) | |
.pipe(jshint()) | |
.pipe(jshint.reporter('jshint-stylish')); | |
}); | |
// ROOT TASKS // --------------------------------------------------------- | |
// Main style task | |
gulp.task('css', function() { | |
return gulp.src('dev/sass/application.scss') | |
.pipe(globbing({extensions: '.scss'})) | |
.pipe(sass()) | |
.on('error', handleError) | |
.pipe(cmq()) // combine all @media queries into the page base | |
.pipe(autoprefixer({cascade: false})) // auto prefix | |
.pipe(minifycss()) // minify everything | |
.pipe(gulp.dest('css')); | |
}); | |
// Main Javascript task | |
gulp.task('js', function() { | |
return gulp.src('dev/js/**/*.js') | |
.pipe(newer('js')) | |
//.pipe(uglify()) | |
.on('error', handleError) | |
.pipe(gulp.dest('js')); | |
}); | |
// Main image task | |
gulp.task('img', function() { | |
return gulp.src('dev/img/**/*.{jpg,jpeg,png,gif,svg,ico}') | |
.pipe(newer('img')) | |
.pipe(imagemin({ | |
optimizationLevel: 5, | |
progressive: true, | |
interlaced: true, | |
svgoPlugins: [{ | |
collapseGroups: false, | |
removeViewBox: false | |
}] | |
})) | |
.on('error', handleError) | |
.pipe(gulp.dest('img')); | |
}); | |
// FUNCTIONS // --------------------------------------------------------- | |
// Initial start function | |
gulp.task('start', ['img'], function() { | |
gulp.start('js', 'css'); | |
}); | |
// Watch function | |
gulp.task('watch', ['start'], function() { | |
gulp.watch('dev/sass/**/*.scss', ['css']); | |
gulp.watch('dev/js/**/*.js', ['js']); | |
gulp.watch('dev/img/**/*', ['img']); | |
livereload.listen(); | |
gulp.watch(['layouts/*.html', 'partials/**/*.html', 'templates/*.html', 'js/**/*.js', 'img/**/*.{jpg,jpeg,png,gif,svg,ico}', 'css/*.css']).on('change', livereload.changed); | |
}); | |
// Default function | |
gulp.task('default', ['watch'], function() { | |
var server = new phpServer(); | |
server.on('listening', function(event) {}); | |
server.on('error', function (event) {}); | |
server.listen( '../../', 8000, 'localhost'); | |
}); | |
// Error reporting function | |
function handleError(err) { | |
console.log(err.toString()); | |
this.emit('end'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment