Last active
January 6, 2016 05:09
-
-
Save chrisl8888/bda4a93bb61308919b64 to your computer and use it in GitHub Desktop.
Gulp + jekyll + sass + connect + livereload
This file contains hidden or 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'), | |
concat = require('gulp-concat'), | |
sass = require ('gulp-ruby-sass'), | |
autoprefixer = require ('gulp-autoprefixer'), | |
uglify = require('gulp-uglify'), | |
imagemin = require('gulp-imagemin'), | |
jekyll = require('gulp-jekyll'), | |
// livereload = require('gulp-livereload'), | |
watch = require('gulp-watch'), | |
jshint = require("gulp-jshint"), | |
deploy = require("gulp-gh-pages"), | |
rename = require("gulp-rename"), | |
minifycss = require("gulp-minify-css"), | |
connect = require('gulp-connect'), | |
jshint = require("gulp-jshint"), | |
bower = require('gulp-bower'), | |
cp = require('child_process'), | |
spawn = require('child_process').spawn, | |
plumber = require('gulp-plumber'), | |
debug = require('gulp-debug'); | |
var paths = { | |
scripts: ['js/*.js'], | |
images: 'img/**/*', | |
sass: ['scss/**/*.scss'], | |
jekyll: ['_layouts/*.html', '_posts/*', '_sites'] | |
}; | |
// gulp.task('bower', function() { | |
// bower() | |
// .pipe(gulp.dest('lib/')); | |
// var vendorStream = gulp.src(['./bower_components/*/*.js']) | |
// .pipe(concat('vendors.js')) | |
// .pipe(gulp.dest('./dist')); | |
// }); | |
// gulp.task('html', function() { | |
// return gulp.src([ + '/*.html', + '/**/*.html', + '/*.md', + '/**/*.md']) | |
// .pipe(connect.reload()); | |
// }) | |
// Run Jekyll Build Asynchronously | |
gulp.task('jekyll', function () { | |
var jekyll = spawn('bundle', ['exec jekyll build']); | |
jekyll.on('exit', function (code) { | |
console.log('-- Finished Jekyll Build --') | |
}); | |
gulp.src(paths.jekyll) | |
.pipe(connect.reload()); | |
}); | |
/* | |
* Server | |
*/ | |
gulp.task('connect', function() { | |
connect.server({ | |
root: __dirname, | |
livereload: true | |
}); | |
}); | |
/* | |
* CSS | |
*/ | |
gulp.task('style', function() { | |
return gulp.src({glob: 'scss/**/*.scss'}) | |
.pipe(plumber()) | |
.pipe(sass({ style: 'compact' })) | |
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1')) | |
.pipe(gulp.dest('css')) | |
.pipe(rename({suffix: '.min'})) | |
.pipe(minifycss()) | |
.pipe(gulp.dest('css')); | |
}); | |
gulp.task('style-dev', function() { | |
return gulp.src('scss/**/*.scss') | |
.pipe(sass({ | |
debugInfo : true, | |
lineNumbers : true, | |
sourcemap: true, | |
// loadPath : 'scss', | |
style : 'expanded' | |
})) | |
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1')) | |
.pipe(gulp.dest('css')); | |
}); | |
/* | |
* Scripts | |
*/ | |
gulp.task('scripts', function() { | |
// Minify and copy all JavaScript (except vendor scripts) | |
return gulp.src(paths.scripts) | |
.pipe(plumber()) | |
.pipe(jshint()) | |
.pipe(jshint.reporter("default")) | |
.pipe(uglify()) | |
.pipe(concat('all.min.js')) | |
.pipe(gulp.dest('js')) | |
.pipe(connect.reload()); | |
}); | |
/* | |
* Images | |
*/ | |
// Copy all static images | |
// gulp.task('images', function() { | |
// return gulp.src(paths.images) | |
// // Pass in options to the task | |
// .pipe(imagemin({optimizationLevel: 5})) | |
// .pipe(gulp.dest('build/img')); | |
// }); | |
/* | |
* Scripts | |
*/ | |
gulp.task('watch', function() { | |
gulp.watch(paths.scripts, ['scripts']); | |
gulp.watch(paths.sass, ['styles-dev']); | |
gulp.watch(['*.html', '*/*.html', '*/*.md', '!_site/**', '!_site/*/**'], ['jekyll']); | |
// gulp.watch(paths.images, ['images']); | |
// When a file in the _site directory changes, tell livereload to reload the page | |
gulp.watch(['_site/*/**']).on('change', function (file) { | |
connect.reload(); | |
}); | |
}); | |
/* | |
* Deploy | |
*/ | |
gulp.task('deploy', function () { | |
gulp.src("./dist/**/*") | |
.pipe(deploy(gitRemoteUrl, remote)); | |
}); | |
// The default task (called when you run `gulp` from cli) | |
gulp.task('default', ['style-dev', 'connect', 'jekyll', 'watch']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment