Last active
August 29, 2015 14:05
-
-
Save bytefade/a3b4fb51097c57cbe349 to your computer and use it in GitHub Desktop.
Gulp
This file contains hidden or 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
// -- include gulp | |
var gulp = require('gulp'); | |
// -- include plug-ins | |
var jshint = require('gulp-jshint'); | |
var changed = require('gulp-changed'); | |
var imagemin = require('gulp-imagemin'); | |
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'); | |
var gutil = require('gulp-util'); | |
var clean = require('gulp-clean'); | |
var watch = require('gulp-watch'); | |
var filesize = require('gulp-filesize'); | |
var rename = require('gulp-rename'); | |
// -- mantendo ambiente limpo | |
gulp.task('clean', function () { | |
return gulp.src(['tmp', /*'build'*/], {read: false}) | |
.pipe(clean()); | |
}); | |
// -- Princpais bibliotecas, seperado dos scripts principais | |
gulp.task('lib', function() { | |
return gulp.src('./src/javascripts/lib/*.js') | |
.pipe(concat('lib.js')) | |
.pipe(gulp.dest('build/javascripts/lib')) | |
.pipe(filesize()) | |
.pipe(uglify()) | |
.pipe(rename('lib.min.js')) | |
.pipe(gulp.dest('build/javascripts/lib/')) | |
.pipe(filesize()) | |
.on('error', gutil.log) | |
}); | |
// -- JS hint task | |
gulp.task('jshint', function() { | |
gulp.src('./src/javascripts/*.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)); | |
}); | |
// JS concat, strip debugging and minify | |
gulp.task('scripts', function() { | |
gulp.src(['./src/javascripts/*.js']) | |
.pipe(concat('javascripts.js')) | |
.pipe(stripDebug()) | |
.pipe(uglify()) | |
.pipe(gulp.dest('./build/javascripts/')); | |
}); | |
// CSS concat, auto-prefix and minify | |
gulp.task('styles', function() { | |
gulp.src(['./src/stylesheet/vendor/*.css','./src/stylesheet/*.css']) | |
.pipe(concat('stylesheet.css')) | |
.pipe(autoprefix('last 2 versions')) | |
.pipe(minifyCSS({keepSpecialComments: 0})) | |
.pipe(gulp.dest('./build/stylesheet/')); | |
}); | |
//-- default gulp task | |
gulp.task('default', function () { | |
// var server = ['jasmine', 'embed']; | |
var client = ['clean', 'imagemin', 'scripts', | |
'styles', 'lib']; | |
//-- watch for JS changes | |
gulp.watch('./src/javascripts/*.js', client); | |
//-- watch for CSS changes | |
gulp.watch('./src/stylesheet/*.css', client); | |
//-- watch for IMAGES changes | |
gulp.watch('./src/images/**/*', client); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment