Skip to content

Instantly share code, notes, and snippets.

@belen-albeza
Created February 5, 2015 18:20
Show Gist options
  • Save belen-albeza/cd55189273efe9315e8e to your computer and use it in GitHub Desktop.
Save belen-albeza/cd55189273efe9315e8e to your computer and use it in GitHub Desktop.
Gulpfile for static templates
/*
Automation for crafting static templates. Features:
- Less for CSS
- Swig templates for HTML (optional, but useful if you have to repeat header, footer, etc.)
- Automatically reload page when Less or Swig files change
- Builds a release into a zip file
Requires the following structure:
.
├── app
| └── images
├── gulpfile.js
├── less
│ └── styles_here.less
│ └── _partials_too.less
├── package.json
└── templates
├── your_swig_templates_here.html
└── _partials_too.html
*/
var gulp = require('gulp');
var connect = require('gulp-connect');
var less = require('gulp-less');
var swig = require('gulp-swig');
var livereload = require('gulp-livereload');
var zip = require('gulp-zip');
gulp.task('connect', function () {
connect.server({
root: ['app', '.tmp']
});
});
gulp.task('less', function () {
gulp.src(['less/*.less', '!less/_*.less'])
.pipe(less({
paths: [__dirname + '/app/less']
}))
.pipe(gulp.dest('.tmp/css'))
.pipe(livereload())
});
gulp.task('templates', function () {
gulp.src(['templates/*.html', '!**/_*.html'])
.pipe(swig({defaults: {cache: false}}))
.pipe(gulp.dest('.tmp'))
.pipe(livereload())
});
gulp.task('watch', ['connect'], function () {
livereload.listen();
gulp.watch('less/*.less', ['less']);
gulp.watch('templates/*.html', ['templates'])
});
gulp.task('release', ['build'], function () {
gulp.src(['app/**/*', '.tmp/**/*'])
.pipe(zip('release.zip'))
.pipe(gulp.dest('.'));
});
gulp.task('build', ['less', 'templates']);
gulp.task('server', ['build', 'watch']);
gulp.task('default', ['build']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment