Created
April 29, 2014 14:08
-
-
Save joshstrange/11401434 to your computer and use it in GitHub Desktop.
Gulp example for co-worker
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 gulp = require('gulp'); | |
var jshint = require('gulp-jshint'); | |
var uglify = require('gulp-uglify'); | |
var notify = require('gulp-notify'); | |
var rename = require('gulp-rename'); | |
var concat = require('gulp-concat'); | |
var ngmin = require('gulp-ngmin'); | |
var clean = require('gulp-clean'); | |
var less = require('gulp-less'); | |
var minifyCSS = require('gulp-minify-css'); | |
var htmlreplace = require('gulp-html-replace'); | |
var argv = require('yargs').argv; | |
gulp.task('default', ['build', 'watch'], function() { | |
// place code for your default task here | |
}); | |
gulp.task('clean', function() { | |
return gulp.src(['www/**/*','.tmp/public'], {read: false}).pipe(clean()); | |
}); | |
gulp.task('scripts', function() { | |
return gulp.src(['assets/js/**/*.js']) | |
.pipe(jshint.reporter('default')) | |
.pipe(concat('app.js')) | |
.pipe(ngmin()) | |
.pipe(gulp.dest('www/js')) | |
.pipe(rename({suffix: '.min'})) | |
.pipe(uglify({mangle: false})) | |
.pipe(gulp.dest('www/js')); | |
}); | |
gulp.task('styles', function() { | |
return gulp.src(['assets/styles/**/*.less']) | |
.pipe(less()) | |
.pipe(concat('app.css')) | |
.pipe(gulp.dest('www/css/')) | |
.pipe(rename({suffix: '.min'})) | |
.pipe(minifyCSS()) | |
.pipe(gulp.dest('www/css/')) | |
}); | |
gulp.task('partials', function() { | |
return gulp.src(['assets/partials/*']) | |
.pipe(gulp.dest('www/partials')); | |
}); | |
gulp.task('images', function() { | |
return gulp.src(['assets/images/*']) | |
.pipe(gulp.dest('www/images')); | |
}); | |
gulp.task('index', function() { | |
return gulp.src('assets/index.html') | |
.pipe(htmlreplace(argv.env == 'prod' ? { | |
'css': 'css/app.min.css', | |
'js': 'js/app.min.js' | |
} : { | |
'css': 'css/app.css', | |
'js': 'js/app.js' | |
})) | |
.pipe(gulp.dest('www/')); | |
}); | |
gulp.task('build', ['clean'], function() { | |
gulp.start('scripts', 'styles', 'partials', 'images', 'index'); | |
}); | |
gulp.task('watch', function() { | |
gulp.watch('assets/index.html', ['index']).on('change', function(event) { | |
console.log('File '+event.path+' was '+event.type+', running tasks...'); | |
}); | |
gulp.watch('assets/styles/**/*.less', ['styles']).on('change', function(event) { | |
console.log('File '+event.path+' was '+event.type+', running tasks...'); | |
}); | |
gulp.watch('assets/js/**/*.js', ['scripts']).on('change', function(event) { | |
console.log('File '+event.path+' was '+event.type+', running tasks...'); | |
}); | |
gulp.watch('assets/partials/*', ['partials']).on('change', function(event) { | |
console.log('File '+event.path+' was '+event.type+', running tasks...'); | |
}); | |
gulp.watch('assets/images/*', ['images']).on('change', function(event) { | |
console.log('File '+event.path+' was '+event.type+', running tasks...'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment