Created
May 17, 2016 12:18
-
-
Save StoneMoe/a30cbebd03304721f0b10f2b4f1db53e to your computer and use it in GitHub Desktop.
My gulp workflow 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 less = require('gulp-less'); | |
var autoprefixer = require('gulp-autoprefixer'); | |
var minifyCSS = require('gulp-minify-css'); | |
var notify = require('gulp-notify'); | |
var gutil = require('gulp-util'); | |
var cp = require('child_process'); | |
var path = require('path'); | |
var uglify = require('gulp-uglify'); | |
var imagemin = require('gulp-imagemin'); | |
var pngquant = require('imagemin-pngquant'); | |
var messages = { | |
jekyllBuild: '<span style="color: grey">Running:</span> $ jekyll build' | |
}; | |
/** | |
* Build the Jekyll Site | |
*/ | |
gulp.task('jekyll-build', function (done) { | |
browserSync.notify(messages.jekyllBuild); | |
return cp.spawn('jekyll', ['build'], {stdio: 'inherit'}) | |
.on('close', done); | |
}); | |
// minifiy js | |
gulp.task('compress', function() { | |
gulp.src('js/*.js') | |
.pipe(uglify()) | |
.pipe(gulp.dest('js/min')) | |
}); | |
// minifiy images | |
gulp.task('images', function () { | |
return gulp.src('images/*') | |
.pipe(imagemin({ | |
progressive: true, | |
svgoPlugins: [{removeViewBox: false}], | |
use: [pngquant()] | |
})) | |
.pipe(gulp.dest('images')); | |
}); | |
// compile LESS | |
gulp.task('less', function () { | |
gulp.src('_less/main.less') | |
.pipe(less({ | |
paths: [ path.join(__dirname, '_less', 'includes') ] | |
})) | |
.pipe(less({compress: true}).on('error', gutil.log)) | |
.pipe(autoprefixer('last 10 versions', 'ie 9')) | |
.pipe(minifyCSS({keepBreaks: false})) | |
.pipe(gulp.dest('css')) | |
.pipe(notify('Less Compiled, Prefixed and Minified')); | |
}); | |
// Watch files | |
gulp.task('watch', function () { | |
gulp.watch('_less/**/*.less', ['less']); | |
gulp.watch(['index.html', '_layouts/*.html', '_posts/*', '**/*.html', '_less/**/*.less', 'js/**/*', 'images/*'], ['jekyll-rebuild']); | |
}); | |
gulp.task('default', ['browser-sync', 'images', 'watch', 'compress']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment