|
| 1 | +// Load plugins |
| 2 | + |
| 3 | +var gulp = require('gulp'), |
| 4 | + gutil = require('gulp-util'), |
| 5 | + watch = require('gulp-watch'), |
| 6 | + lr = require('tiny-lr'), |
| 7 | + server = lr(), |
| 8 | + livereload = require('gulp-livereload'), |
| 9 | + prefix = require('gulp-autoprefixer'), |
| 10 | + minifyCSS = require('gulp-minify-css'), |
| 11 | + sass = require('gulp-ruby-sass'), |
| 12 | + imagemin = require('gulp-imagemin'), |
| 13 | + svgmin = require('gulp-svgmin'), |
| 14 | + csslint = require('gulp-csslint'); |
| 15 | + |
| 16 | + |
| 17 | +// Task to minify all css files in the css directory |
| 18 | +gulp.task('minify-css', function(){ |
| 19 | + gulp.src('./css/*.css') |
| 20 | + .pipe(minifyCSS({keepSpecialComments: 0})) |
| 21 | + .pipe(gulp.dest('./css/')); |
| 22 | +}); |
| 23 | + |
| 24 | +// Reload html |
| 25 | +gulp.task('reload', function(){ |
| 26 | + gulp.src('*.html') |
| 27 | + .pipe(watch(function(files) { |
| 28 | + return files.pipe(livereload(server)); |
| 29 | + })); |
| 30 | +}); |
| 31 | + |
| 32 | + |
| 33 | +// Task to optmize and minify images |
| 34 | +gulp.task('minify-img', function() { |
| 35 | + return gulp.src('./img/**/*') |
| 36 | + .pipe((imagemin({ optimizationLevel: 5, progressive: true, interlaced: true }))) |
| 37 | + .pipe(gulp.dest('./img')); |
| 38 | +}); |
| 39 | + |
| 40 | +// Task to optimize and minify svg |
| 41 | +gulp.task('minify-svg', function(){ |
| 42 | + gulp.src('./img/svg') |
| 43 | + .pipe(svgmin()) |
| 44 | + .pipe(gulp.dest('./img/svg')); |
| 45 | +}); |
| 46 | + |
| 47 | + |
| 48 | +// Use csslint without box-sizing or compatible vendor prefixes (these |
| 49 | +// don't seem to be kept up to date on what to yell about) |
| 50 | +gulp.task('csslint', function(){ |
| 51 | + gulp.src('./css/*.css') |
| 52 | + .pipe(csslint({ |
| 53 | + 'compatible-vendor-prefixes': false, |
| 54 | + 'box-sizing': false, |
| 55 | + 'important': false |
| 56 | + })) |
| 57 | + .pipe(csslint.reporter()); |
| 58 | + |
| 59 | +}); |
| 60 | + |
| 61 | +// Task that compiles scss files down to good old css |
| 62 | +gulp.task('pre-process', function(){ |
| 63 | + gulp.src('./sass/fluidity.scss') |
| 64 | + .pipe(watch(function(files) { |
| 65 | + return files.pipe(sass({loadPath: ['./sass/'], style: "compact"})) |
| 66 | + .pipe(prefix()) |
| 67 | + .pipe(gulp.dest('./css/')) |
| 68 | + .pipe(livereload(server)); |
| 69 | + })); |
| 70 | +}); |
| 71 | + |
| 72 | +/* |
| 73 | + DEFAULT TASK |
| 74 | +
|
| 75 | + • Process sass and lints outputted css |
| 76 | + • Outputted css is run through autoprefixer |
| 77 | + • Sends updates to any files in directory to browser for |
| 78 | + automatic reloading |
| 79 | +
|
| 80 | +*/ |
| 81 | +gulp.task('default', function(){ |
| 82 | + server.listen(35729, function (err) { |
| 83 | + gulp.watch(['*.html', './sass/*.scss'], function(event) { |
| 84 | + gulp.run('reload', 'pre-process', 'csslint'); |
| 85 | + }); |
| 86 | + }); |
| 87 | +}); |
| 88 | + |
| 89 | +gulp.task('production', function(){ |
| 90 | + gulp.run('minify-css', 'minify-img', 'minify-svg'); |
| 91 | +}); |
| 92 | + |
0 commit comments