Created
June 1, 2014 10:43
-
-
Save jegtnes/780e68e85b7ca8008079 to your computer and use it in GitHub Desktop.
The Gulpfile I created for the blogpost http://jegtnes.co.uk/blog/using-gulp-with-uncss-in-ghost-for-tiny-assets/, detailing how to use UnCSS and Gulp for Ghost.
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
var gulp = require('gulp'); | |
var sass = require('gulp-sass'); // skip this if you're working with vanilla CSS | |
var rename = require('gulp-rename'); | |
var cmq = require('gulp-combine-media-queries'); | |
var uncss = require('gulp-uncss'); | |
var download = require('download'); | |
var cssmin = require('gulp-cssmin'); | |
var clean = require('gulp-clean'); | |
var xml2js = require('gulp-xml2js'); | |
// Upon runnning styles-build, this will be populated with all blog posts too | |
// See tasks find-site-files, create-sitemap, and download-rss-feed | |
var filesToUncss = [ | |
'http://jegtnes.co.uk', | |
'http://jegtnes.co.uk/styleguide', | |
'http://jegtnes.co.uk/portfolio', | |
'http://jegtnes.co.uk/contact' | |
]; | |
gulp.task('styles-build', ['find-site-files'], function() { | |
return gulp.src('scss/style.scss') //you probably want to change this | |
.pipe(sass()) // skip this if you're working with vanilla CSS | |
.pipe(rename({suffix: '.min'})) | |
.pipe(cmq()) | |
.pipe(uncss({ | |
html: filesToUncss | |
})) | |
.pipe(cssmin()) | |
.pipe(gulp.dest('assets/css')); | |
}) | |
gulp.task('download-rss-feed', function(callback) { | |
dl = download({ | |
url: 'http://jegtnes.co.uk/rss', | |
name: 'rss.xml' | |
}, './') | |
dl.once('close', function() { | |
callback(); | |
}); | |
}); | |
gulp.task('create-sitemap', ['download-rss-feed'], function() { | |
return gulp.src('./rss.xml') | |
.pipe(xml2js()) | |
.pipe(rename('rss.json')) | |
.pipe(gulp.dest('./')); | |
}); | |
gulp.task('find-site-files', ['create-sitemap'], function() { | |
var json = require('./rss.json'); | |
json.rss.channel[0].item.forEach(function(value) { | |
link = value.link[0] | |
filesToUncss.push(link); | |
}) | |
return gulp.src(['rss.json', 'rss.xml'], {read: false}) | |
.pipe(clean()); | |
}); | |
// The default task (called when you run `gulp` from cli) | |
gulp.task('default', ['styles-build']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment