Created
April 29, 2015 23:48
-
-
Save mckernanin/782102dd71cacf3057d6 to your computer and use it in GitHub Desktop.
Gulp File
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'); | |
var browserSync = require('browser-sync'); | |
var reload = browserSync.reload; | |
var sass = require('gulp-sass'); | |
var autoprefixer = require('gulp-autoprefixer'); | |
var imagemin = require('gulp-imagemin'); | |
var pngquant = require('imagemin-pngquant'); | |
var uglify = require('gulp-uglify'); | |
var plumber = require('gulp-plumber'); | |
var debug = require('gulp-debug'); | |
// browser-sync task for starting the server. | |
gulp.task('browser-sync', function() { | |
//watch files | |
var files = [ | |
'./build/style.css', | |
'./**/*.php', | |
'./js/*.js' | |
]; | |
//initialize browsersync | |
browserSync.init(files, { | |
//browsersync with a php server | |
proxy: "local.dev", | |
notify: false | |
}); | |
}); | |
// copy all php files to build directory on save | |
gulp.task('copy-php', function() { | |
gulp.src('./*.php') | |
.pipe(gulp.dest('./build')); | |
gulp.src('./inc/*.php') | |
.pipe(gulp.dest('./build/inc')); | |
}); | |
// copy all font files to build directory | |
gulp.task('copy-fonts', function() { | |
gulp.src('./fonts/*.*') | |
.pipe(gulp.dest('./build/fonts')); | |
}); | |
// optimize all images | |
gulp.task('images', function() { | |
return gulp.src('{./images/*, ./screenshot.png}') | |
.pipe(imagemin({ | |
progressive: true, | |
svgoPlugins: [ | |
{removeViewBox: false}, | |
{cleanupIDs: false} | |
], | |
use: [pngquant()] | |
})) | |
.pipe(plumber({ | |
errorHandler: function (err) { | |
console.log(err); | |
this.emit('end'); | |
} | |
})) | |
.pipe(gulp.dest('./build')); | |
}); | |
// minify javascript | |
gulp.task('js', function() { | |
return gulp.src('js/*.js') | |
.pipe(uglify()) | |
.pipe(plumber({ | |
errorHandler: function (err) { | |
console.log(err); | |
this.emit('end'); | |
} | |
})) | |
.pipe(gulp.dest('./build/js')); | |
}); | |
// Sass task, will run when any SCSS files change & BrowserSync | |
// will auto-update browsers | |
gulp.task('sass', function () { | |
return gulp.src('css/*.scss') | |
.pipe(plumber({ | |
errorHandler: function (err) { | |
console.log(err); | |
this.emit('end'); | |
} | |
})) | |
.pipe(sass()) | |
.pipe(autoprefixer({ | |
browsers: ['last 2 versions'], | |
cascade: false | |
})) | |
.pipe(gulp.dest('./build')) | |
.pipe(reload({stream:true})); | |
}); | |
// copy all build files to local www directory | |
gulp.task('copy-to-vagrant', function() { | |
gulp.src('./build/**/*') | |
.pipe(debug({title: 'vagrant-copy:'})) | |
.pipe(gulp.dest('/absolute/path/to/local/webroot')); | |
}); | |
// Default task to be run with `gulp` | |
gulp.task('default', ['sass', 'browser-sync', 'images', 'js', 'copy-to-vagrant'], function () { | |
gulp.watch("css/**/*.scss", ['sass']); | |
gulp.watch("./**/*.php", ['copy-php']); | |
gulp.watch("./images/*", ['images']); | |
gulp.watch("js/*.js", ['js']); | |
gulp.watch("./build/**/*"), ['copy-to-vagrant']; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment