Skip to content

Instantly share code, notes, and snippets.

@jayperryworks
Last active August 29, 2015 14:02
Show Gist options
  • Save jayperryworks/24453a5652e16f32ee43 to your computer and use it in GitHub Desktop.
Save jayperryworks/24453a5652e16f32ee43 to your computer and use it in GitHub Desktop.
gulpfile for jekyll (github pages, uncompiled version)
'use strict';
// generated on 2014-05-21 using generator-gulp-webapp 0.1.0
var gulp = require('gulp');
// useful file paths
var path = {
app: 'app',
dist: 'dist',
bower: '_bower_components',
assets: 'assets',
css: 'assets/styles',
js: 'assets/scripts',
img: 'assets/images',
fonts: 'assets/fonts'
};
// load plugins
var $ = require('gulp-load-plugins')();
gulp.task('styles', function () {
return gulp.src('app/' + path.css + '/main.scss')
.pipe($.rubySass({
style: 'expanded',
bundleExec: 'true',
lineNumbers: 'true',
loadPath: 'app/' + path.bower,
precision: 10
}))
.pipe($.autoprefixer('last 1 version'))
.pipe(gulp.dest('.tmp/' + path.css))
.pipe($.size());
});
gulp.task('styles-serve', function () {
return gulp.src('app/' + path.css + '/main.scss')
.pipe($.rubySass({
style: 'expanded',
bundleExec: 'true',
lineNumbers: 'true',
loadPath: 'app/' + path.bower,
precision: 10
}))
.pipe($.autoprefixer('last 1 version'))
.pipe(gulp.dest('dist/' + path.css))
.pipe($.size());
});
gulp.task('scripts', function () {
return gulp.src('app/' + path.js + '/**/*.js')
.pipe($.jshint())
.pipe($.jshint.reporter(require('jshint-stylish')))
.pipe($.size());
});
gulp.task('scripts-serve', function () {
return gulp.src('app/' + path.js + '/**/*.js')
.pipe($.jshint())
.pipe($.jshint.reporter(require('jshint-stylish')))
.pipe(gulp.dest('dist/' + path.js))
.pipe($.size());
});
// Runs the build command for Jekyll to compile the site locally
// Only used for local server -- for build, pull uncompiled files and send to github
gulp.task('jekyll', function() {
return gulp.src('')
.pipe($.exec("jekyll build"));
});
gulp.task('html', ['styles', 'scripts'], function () {
var jsFilter = $.filter('**/*.js');
var cssFilter = $.filter('**/*.css');
return gulp.src('app/**/*{.html,.md}')
.pipe($.useref.assets({searchPath: '{.tmp,app}'}))
.pipe(jsFilter)
.pipe($.uglify())
.pipe(jsFilter.restore())
.pipe(cssFilter)
.pipe($.csso())
.pipe(cssFilter.restore())
.pipe($.useref.restore())
.pipe($.useref())
.pipe(gulp.dest('dist'))
.pipe($.size());
});
gulp.task('images', function () {
return gulp.src('app/' + path.img + '/**/*')
.pipe($.cache($.imagemin({
optimizationLevel: 3,
progressive: true,
interlaced: true
})))
.pipe(gulp.dest('dist/' + path.img))
.pipe($.size());
});
gulp.task('fonts', function () {
return gulp.src('app/assets/fonts/**/*')
// .pipe($.filter('*.{eot,svg,ttf,woff}'))
// .pipe($.flatten())
.pipe(gulp.dest('dist/' + path.fonts))
.pipe($.size());
});
gulp.task('extras', function () {
return gulp.src(['app/*.*', '!app/*.html'], { dot: true })
.pipe(gulp.dest('dist'));
});
gulp.task('clean', function () {
return gulp.src(['.tmp', 'dist/**/*', '!dist/{.git,.gitignore,CNAME,README.md,LICENSE}'], { read: false }).pipe($.clean());
});
gulp.task('build', ['html', 'images', 'fonts', 'extras']);
gulp.task('default', ['clean'], function () {
gulp.start('build');
});
gulp.task('connect', function () {
var connect = require('connect');
var app = connect()
.use(require('connect-livereload')({ port: 35729 }))
.use(connect.static('dist'))
.use(connect.static('.tmp'))
.use(connect.directory('dist'));
require('http').createServer(app)
.listen(9000)
.on('listening', function () {
console.log('Started connect web server on http://localhost:9000');
});
});
gulp.task('serve', ['connect', 'styles-serve'], function () {
require('opn')('http://localhost:9000');
});
// inject bower components
gulp.task('wiredep', function () {
var wiredep = require('wiredep').stream;
gulp.src('app/' + path.css + '/*.scss')
.pipe(wiredep({
directory: 'app/' + path.bower
}))
.pipe(gulp.dest('app/styles'));
gulp.src('app/*.html')
.pipe(wiredep({
directory: 'app/' + path.bower
}))
.pipe(gulp.dest('app'));
});
gulp.task('watch', ['images', 'fonts', 'styles-serve', 'scripts-serve', 'jekyll', 'extras', 'connect', 'serve'], function () {
var server = $.livereload();
// watch for changes
gulp.watch([
'dist/**/*.html',
'{.tmp,dist}/' + path.css + '/**/*.css',
'dist/' + path.js + '/**/*.js',
'dist/' + path.img + '/**/*'
]).on('change', function (file) {
server.changed(file.path);
});
gulp.watch('app/**/*.html', ['jekyll']);
gulp.watch('app/**/*.md', ['jekyll']);
gulp.watch('**/*.yml', ['jekyll']);
gulp.watch('app/' + path.css + '/**/*.scss', ['styles-serve']);
gulp.watch('app/' + path.js + '/**/*.js', ['scripts-serve']);
gulp.watch('app/' + path.img + '/**/*', ['images']);
gulp.watch('bower.json', ['wiredep']);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment