##A Nunjucks task for Gulp
Created
April 26, 2016 09:22
-
-
Save gotpop/ce086a4e784f1b27b07581dd3021ef90 to your computer and use it in GitHub Desktop.
A Nunjucks Gulp task.
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
//////////////////////////////////////////////////////////////////////////////////// | |
// Require | |
//////////////////////////////////////////////////////////////////////////////////// | |
var gulp = require('gulp'), | |
prefix = require('gulp-autoprefixer'), | |
notify = require('gulp-notify'), | |
browserSync = require('browser-sync'), | |
reload = browserSync.reload, | |
sass = require('gulp-ruby-sass'), | |
sourcemaps = require('gulp-sourcemaps'), | |
rename = require('gulp-rename'), | |
plumber = require('gulp-plumber'), | |
uncss = require('gulp-uncss'), | |
nunjucksRender = require('gulp-nunjucks-render'), | |
minifyCss = require('gulp-minify-css'), | |
data = require('gulp-data'); | |
/////////////////////////////////////////////////////////////////////////////////// | |
// Compile HTML with nunjucks | |
/////////////////////////////////////////////////////////////////////////////////// | |
gulp.task('nunjucks', function() { | |
nunjucksRender.nunjucks.configure(['build-assets/html/templates/']); | |
return gulp.src('build-assets/html/pages/**/*.+(html|nunjucks)') | |
.pipe(data(function() { | |
return require('./build-assets/data/data.json') | |
})) | |
.pipe(nunjucksRender()) | |
.pipe(gulp.dest('build')) | |
.pipe(reload({stream:true})) | |
.pipe(notify({ message: 'Build HTML task complete' })); | |
}); | |
/////////////////////////////////////////////////////////////////////////////////// | |
// Compile Sass | |
/////////////////////////////////////////////////////////////////////////////////// | |
gulp.task('sass', function () { | |
gulp.src('./build-assets/sass/**/**/*.scss') | |
.pipe(sass({sourcemap: true, style: 'compact'})) | |
.pipe(prefix("last 3 version", "> 1%", "ie 8", "ie 9")) | |
.pipe(minifyCss({compatibility: 'ie8'})) | |
.pipe(gulp.dest('./build/assets/css')) | |
.pipe(reload({stream:true})) | |
.pipe(notify({ message: 'Styles task complete' })); | |
}); | |
/////////////////////////////////////////////////////////////////////////////////// | |
// browser-sync task for starting the server. | |
/////////////////////////////////////////////////////////////////////////////////// | |
gulp.task('browser-sync', function() { | |
browserSync({ | |
port: 2020, | |
server: { | |
baseDir: "./build" | |
} | |
}); | |
}); | |
/////////////////////////////////////////////////////////////////////////////////// | |
// Watch for HTML/SASS changes | |
/////////////////////////////////////////////////////////////////////////////////// | |
gulp.task('watch', function () { | |
gulp.watch('./build-assets/sass/**/*.scss', ['sass']); | |
gulp.watch('./build-assets/html/**/*.html', ['nunjucks', 'browser-sync']); | |
}); | |
/////////////////////////////////////////////////////////////////////////////////// | |
// Default tasks | |
/////////////////////////////////////////////////////////////////////////////////// | |
gulp.task('default', ['watch', 'browser-sync']); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment