Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Gulp file for Jekyll, with Sass, Autoprefixer, and browsersync
var gulp = require('gulp'),
sass = require('gulp-ruby-sass'),
autoprefixer = require('gulp-autoprefixer'),
minifycss = require('gulp-minify-css'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
clean = require('gulp-clean'),
concat = require('gulp-concat'),
notify = require('gulp-notify'),
cache = require('gulp-cache'),
plumber = require('gulp-plumber'),
browserSync = require('browser-sync'),
cp = require('child_process');
gulp.task('styles', function() {
return gulp.src('src/sass/*.sass')
.pipe(sass({ style: 'expanded' }))
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.pipe(rename({suffix: '.min'}))
.pipe(notify({ message: 'Styles task complete' }));
gulp.task('scripts', function() {
return gulp.src('src/javascripts/**/*.js')
.pipe(rename({suffix: '.min'}))
.pipe(notify({ message: 'Scripts task complete' }));
gulp.task('clean', function() {
return gulp.src(['stylesheets', 'javascripts'], {read: false})
* Build the Jekyll Site
gulp.task('jekyll-build', function (done) {
browserSync.notify('Building Jekyll');
return cp.spawn('jekyll', ['build'], {stdio: 'inherit'})
.on('close', done);
* Rebuild Jekyll & do page reload
gulp.task('jekyll-rebuild', ['jekyll-build'], function () {
* Wait for jekyll-build, then launch the Server
gulp.task('browser-sync', ['jekyll-build'], function() {
browserSync.init(null, {
server: {
baseDir: '_site'
host: "localhost"
gulp.task('watch', function() {
// Watch .sass files'src/sass/**/*.sass', ['styles']);
// Watch .js files'src/javascripts/**/*.js', ['scripts']);['index.html', '_layouts/*.html', '_posts/*'], ['jekyll-rebuild']);
gulp.task('default', ['clean'], function() {
gulp.start('styles', 'scripts', 'browser-sync', 'watch');

This comment has been minimized.

Copy link

@dmitriz dmitriz commented Jul 30, 2014

What about css-lint?


This comment has been minimized.

Copy link

@dmitriz dmitriz commented Jul 30, 2014

I am using this:

'use strict';
// import local config
var config = require('./Gulp.conf.js');

// lazy load plugins - $$.clean instead of requiring it
var $$ = require('gulp-load-plugins')();

// compiling css files
gulp.task('css', function () {
  return gulp.src(config.paths.css)

Note the changed plugin, so only changed or new files are compiled.

Then I am separately concatenating minimized files:

// concat minimized JS and CSS files
gulp.task('concat', function(){

  return [   {min: config.paths.min.js, concat: config.paths.concat.js}
    , {min: config.paths.min.css, concat: config.paths.concat.css} ].forEach(function (paths) {

This comment has been minimized.

Copy link
Owner Author

@donovanh donovanh commented Jan 13, 2015

Thanks @dmitriz that's most helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.