-
-
Save codegaze/8a6d49a67bcba2f628d5939d8f2cb658 to your computer and use it in GitHub Desktop.
Example of working around gulpfile.js error in this blog post: https://codegaze.github.io/2016/01/09/a-jekyll-workflow-with-gulp/
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
// Require all the things | |
var gulp = require('gulp'), | |
sass = require('gulp-sass'), | |
gutil = require('gulp-util'), | |
plumber = require('gulp-plumber'), | |
rename = require('gulp-rename'), | |
minifyCSS = require('gulp-clean-css'), | |
prefixer = require('gulp-autoprefixer'), | |
connect = require('gulp-connect'), | |
cp = require('child_process'); | |
// Set the path variables | |
var base_path = './', | |
src = base_path + '_dev/src', | |
dist = base_path + 'assets', | |
paths = { | |
js: src + '/js/*.js', | |
scss: [src + '/sass/*.scss', | |
src + '/sass/**/* .scss', | |
src + '/sass/**/**/*.scss' | |
], | |
jekyll: ['index.html', '_posts/*', '_layouts/*', '_includes/*', 'assets/*', 'assets/**/*'] | |
}; | |
// Compile sass to css | |
gulp.task('compile-sass', function() { | |
return gulp.src(paths.scss) | |
.pipe(plumber(function(error) { | |
gutil.log(gutil.colors.red(error.message)); | |
gulp.task('compile-sass').emit('end'); | |
})) | |
.pipe(sass()) | |
.pipe(prefixer('last 3 versions', 'ie 9')) | |
.pipe(minifyCSS()) | |
.pipe(rename({ dirname: dist + '/css' })) | |
.pipe(gulp.dest('./')); | |
}); | |
// Rebuild Jekyll | |
gulp.task('build-jekyll', function(code) { | |
return cp.spawn('jekyll', ['build'], { stdio: 'inherit' }) | |
.on('error', function(error) { gutil.log(gutil.colors.red(error.message)); }) | |
.on('close', code); | |
}); | |
// Setup Server | |
gulp.task('server', function() { | |
connect.server({ | |
root: ['_site'], | |
port: 4000 | |
}); | |
}); | |
// Watch files | |
gulp.task('watch', function() { | |
gulp.watch(paths.scss, ['compile-sass']); | |
gulp.watch(paths.jekyll, ['build-jekyll']); | |
}); | |
// Start Everything with the default task | |
gulp.task('default', ['compile-sass', 'build-jekyll', 'server', 'watch']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment