Skip to content

Instantly share code, notes, and snippets.

@alexjlockwood
Last active November 20, 2016 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alexjlockwood/9a4201b5a4b47c3f1c3de69dde4e8ece to your computer and use it in GitHub Desktop.
Save alexjlockwood/9a4201b5a4b47c3f1c3de69dde4e8ece 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/
// 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']);
@codegaze
Copy link

codegaze commented Nov 20, 2016

Hey @alexjlockwood I fixed some indentation stuff here otherwise, LGTM. I need to change the minify-css to clean-css in the post. A lot of things have changed since then (to Jekyll too). Thanks for helping out! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment