Last active
June 22, 2016 19:57
-
-
Save adrianvalenz/9b91c69eab431314dbeefeee48f5aef9 to your computer and use it in GitHub Desktop.
Gulpfile for Jekyll - BrowserSync, Sass, & Autoprefixer.
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'); | |
var browserSync = require('browser-sync'); | |
var sass = require('gulp-sass'); | |
var prefix = require('gulp-autoprefixer'); | |
var cp = require('child_process'); | |
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); | |
}); | |
// Rebuild Jekyll & do page reload | |
gulp.task('jekyll-rebuild', ['jekyll-build'], function () { | |
browserSync.reload(); | |
}); | |
// Wait for jekyll-build, then launch the Server | |
gulp.task('browser-sync', ['sass', 'jekyll-build'], function() { | |
browserSync({ | |
server: { | |
baseDir: '_site' | |
} | |
}); | |
}); | |
// Compile files from _scss into both _site/css (for live injecting) and site (for future jekyll builds) | |
gulp.task('sass', function () { | |
return gulp.src('css/style.scss') | |
.pipe(sass({ | |
includePaths: ['css'], | |
onError: browserSync.notify | |
})) | |
.pipe(prefix(['last 15 versions', '> 1%', 'ie 8', 'ie 7'], { cascade: true })) | |
.pipe(gulp.dest('_site/css')) | |
.pipe(browserSync.reload({stream:true})) | |
.pipe(gulp.dest('css')); | |
}); | |
// Watch scss and jade files for changes & recompile | |
// Watch html/md files, run jekyll & reload BrowserSync | |
gulp.task('watch', function () { | |
gulp.watch('css/**', ['sass']); | |
gulp.watch(['index.html', '*.html', '_includes/*.html', '_layouts/*.html', '_posts/**', 'pages/**'],['jekyll-rebuild']); | |
}); | |
// Default task, running just `gulp` will compile the sass, | |
// compile the jekyll site, launch BrowserSync & watch files. | |
gulp.task('default', ['browser-sync', 'watch']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment