Created
September 2, 2014 09:58
-
-
Save merin83/a46c55726b1d18f73fbd to your computer and use it in GitHub Desktop.
This is a sample gulp file created for learning
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 changed = require('gulp-changed'); | |
var imagemin = require('gulp-imagemin'); | |
var minifyHTML = require('gulp-minify-html'); | |
var gulp = require('gulp'); | |
var jshint = require('gulp-jshint'); | |
var concat = require('gulp-concat'); | |
var stripDebug = require('gulp-strip-debug'); | |
var uglify = require('gulp-uglify'); | |
var autoprefix = require('gulp-autoprefixer'); | |
var minifyCSS = require('gulp-minify-css'); | |
// JS hint task | |
gulp.task('jshint', function() { | |
gulp.src('./src/scripts/*.js') | |
.pipe(jshint()) | |
.pipe(jshint.reporter('default')); | |
}); | |
// minify new images | |
gulp.task('imagemin', function() { | |
var imgSrc = './src/images/**/*', | |
imgDst = './build/images'; | |
gulp.src(imgSrc) | |
.pipe(changed(imgDst)) | |
.pipe(imagemin()) | |
.pipe(gulp.dest(imgDst)); | |
}); | |
// minify new or changed HTML pages | |
gulp.task('htmlpage', function() { | |
var htmlSrc = './src/*.html', | |
htmlDst = './build'; | |
gulp.src(htmlSrc) | |
.pipe(changed(htmlDst)) | |
.pipe(minifyHTML()) | |
.pipe(gulp.dest(htmlDst)); | |
}); | |
// JS concat, strip debugging and minify | |
gulp.task('scripts', function() { | |
gulp.src(['./src/scripts/lib.js','./src/scripts/*.js']) | |
.pipe(concat('script.js')) | |
.pipe(stripDebug()) | |
.pipe(uglify()) | |
.pipe(gulp.dest('./build/scripts/')); | |
}); | |
// CSS concat, auto-prefix and minify | |
gulp.task('styles', function() { | |
gulp.src(['./src/styles/*.css']) | |
.pipe(concat('styles.css')) | |
.pipe(autoprefix('last 2 versions')) | |
.pipe(minifyCSS()) | |
.pipe(gulp.dest('./build/styles/')); | |
}); | |
// default gulp task | |
gulp.task('default', ['imagemin', 'htmlpage', 'scripts', 'styles'], function() { | |
}); | |
// watch for HTML changes | |
gulp.watch('./src/*.html', function() { | |
gulp.run('htmlpage'); | |
}); | |
// watch for JS changes | |
gulp.watch('./src/scripts/*.js', function() { | |
gulp.run('jshint', 'scripts'); | |
}); | |
// watch for CSS changes | |
gulp.watch('./src/styles/*.css', function() { | |
gulp.run('styles'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment