Skip to content

Instantly share code, notes, and snippets.

@johnstew
Created December 1, 2015 21:45
Show Gist options
  • Save johnstew/e906de29172d5d0f532d to your computer and use it in GitHub Desktop.
Save johnstew/e906de29172d5d0f532d to your computer and use it in GitHub Desktop.
Gulp setup with Swig.
'use strict';
var gulp = require('gulp');
var sass = require('gulp-sass');
var swig = require('gulp-swig');
var clean = require('gulp-clean');
var connect = require('gulp-connect');
var watch = require('gulp-watch');
var batch = require('gulp-batch');
var imagemin = require('gulp-imagemin');
var pngquant = require('imagemin-pngquant');
var config = {
dev: {
sass: 'dev/sass/**/*.scss',
html: './dev/html/**/*.html',
images: './dev/img/*'
},
prod: {
css: 'prod/css',
html: './prod/',
images: './prod/images/'
},
clean: {
html: './prod/partials/'
}
};
gulp.task('clean', function(){
gulp.src(config.clean.html, {read: false})
.pipe(clean());
});
gulp.task('imagemin', function(){
gulp.src(config.dev.images)
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngquant()]
}))
.pipe(gulp.dest(config.prod.images));
});
gulp.task('connect', function(){
connect.server({
root: config.prod.html,
livereload: true
});
});
gulp.task('html', function(){
gulp.src(config.prod.html+'*.html')
.pipe(connect.reload());
});
gulp.task('swig', function() {
gulp.src(config.dev.html)
.pipe(swig({defaults: { cache: false }}))
.pipe(gulp.dest(config.prod.html));
});
gulp.task('sass', function(){
gulp.src(config.dev.sass)
.pipe(sass({
includePaths: require('node-bourbon').includePaths
}).on('error', sass.logError))
.pipe(gulp.dest(config.prod.css));
});
gulp.task('watch', function(){
watch(config.dev.sass, batch(function (events, done) {
gulp.start('sass', done);
}));
watch(config.dev.html, batch(function (events, done) {
gulp.start('swig', done);
}));
watch(config.dev.images, batch(function (events, done) {
gulp.start('imagemin', done);
}));
watch([config.prod.html+'*.html',config.prod.css+'/main.css',config.prod.images+'.{jpg,png}'], batch(function (events, done) {
gulp.start('html', done);
}));
});
gulp.task('default', ['sass','swig','connect','imagemin','watch']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment