|
| 1 | +var gulp = require('gulp'); |
| 2 | +var browserSync = require('browser-sync'); |
| 3 | +var sass = require('gulp-sass'); |
| 4 | +var prefix = require('gulp-autoprefixer'); |
| 5 | +var cp = require('child_process'); |
| 6 | + |
| 7 | +var messages = { |
| 8 | + jekyllBuild: '<span style="color: grey">Running:</span> $ jekyll build' |
| 9 | +}; |
| 10 | + |
| 11 | +/** |
| 12 | + * Build the Jekyll Site |
| 13 | + */ |
| 14 | +gulp.task('jekyll-build', function (done) { |
| 15 | + browserSync.notify(messages.jekyllBuild); |
| 16 | + return cp.spawn('jekyll', ['build'], {stdio: 'inherit'}) |
| 17 | + .on('close', done); |
| 18 | +}); |
| 19 | + |
| 20 | +/** |
| 21 | + * Rebuild Jekyll & do page reload |
| 22 | + */ |
| 23 | +gulp.task('jekyll-rebuild', ['jekyll-build'], function () { |
| 24 | + browserSync.reload(); |
| 25 | +}); |
| 26 | + |
| 27 | +/** |
| 28 | + * Wait for jekyll-build, then launch the Server |
| 29 | + */ |
| 30 | +gulp.task('browser-sync', ['sass', 'jekyll-build'], function() { |
| 31 | + browserSync({ |
| 32 | + server: { |
| 33 | + baseDir: '_site' |
| 34 | + } |
| 35 | + }); |
| 36 | +}); |
| 37 | + |
| 38 | +/** |
| 39 | + * Compile files from _scss into both _site/css (for live injecting) and site (for future jekyll builds) |
| 40 | + */ |
| 41 | +gulp.task('sass', function () { |
| 42 | + return gulp.src('_scss/main.scss') |
| 43 | + .pipe(sass({ |
| 44 | + includePaths: ['scss'], |
| 45 | + onError: browserSync.notify |
| 46 | + })) |
| 47 | + .pipe(prefix(['last 15 versions', '> 1%', 'ie 8', 'ie 7'], { cascade: true })) |
| 48 | + .pipe(gulp.dest('_site/css')) |
| 49 | + .pipe(browserSync.reload({stream:true})) |
| 50 | + .pipe(gulp.dest('css')); |
| 51 | +}); |
| 52 | + |
| 53 | +/** |
| 54 | + * Watch scss files for changes & recompile |
| 55 | + * Watch html/md files, run jekyll & reload BrowserSync |
| 56 | + */ |
| 57 | +gulp.task('watch', function () { |
| 58 | + gulp.watch('_scss/*.scss', ['sass']); |
| 59 | + gulp.watch(['index.html', '_layouts/*.html', '_posts/*'], ['jekyll-rebuild']); |
| 60 | +}); |
| 61 | + |
| 62 | +/** |
| 63 | + * Default task, running just `gulp` will compile the sass, |
| 64 | + * compile the jekyll site, launch BrowserSync & watch files. |
| 65 | + */ |
| 66 | +gulp.task('default', ['browser-sync', 'watch']); |
0 commit comments