Last active
August 29, 2015 14:03
-
-
Save mhulse/b6563ce64e95a884bb6b to your computer and use it in GitHub Desktop.
Testing gulp. Posting code here for feedback.
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
var gulp = require('gulp'); | |
var coffee = require('gulp-coffee'); | |
var concat = require('gulp-concat'); | |
var uglify = require('gulp-uglify'); | |
var imagemin = require('gulp-imagemin'); | |
var del = require('del'); | |
var paths = { | |
scripts: ['client/js/**/*.coffee', '!client/external/**/*.coffee'], | |
images: 'client/img/**/*' | |
}; | |
// Not all tasks need to use streams | |
// A gulpfile is just another node program and you can use all packages available on npm | |
gulp.task('clean', function(cb) { | |
// You can use multiple globbing patterns as you would with `gulp.src` | |
del(['build'], cb); | |
}); | |
gulp.task('scripts', ['clean'], function() { | |
// Minify and copy all JavaScript (except vendor scripts) | |
return gulp.src(paths.scripts) | |
.pipe(coffee()) | |
.pipe(uglify()) | |
.pipe(concat('all.min.js')) | |
.pipe(gulp.dest('build/js')); | |
}); | |
// Copy all static images | |
gulp.task('images', ['clean'], function() { | |
return gulp.src(paths.images) | |
// Pass in options to the task | |
.pipe(imagemin({optimizationLevel: 5})) | |
.pipe(gulp.dest('build/img')); | |
}); | |
// Rerun the task when a file changes | |
gulp.task('watch', function() { | |
gulp.watch(paths.scripts, ['scripts']); | |
gulp.watch(paths.images, ['images']); | |
}); | |
// The default task (called when you run `gulp` from cli) | |
gulp.task('default', ['watch', 'scripts', 'images']); |
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
{ | |
"name": "test", | |
"version": "0.0.0", | |
"description": "...", | |
"main": "gulpfile.js", | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"gulp": "~3", | |
"gulp-coffee": "^2.0.1", | |
"gulp-concat": "^2.2.0", | |
"gulp-imagemin": "^0.6.1", | |
"gulp-uglify": "^0.3.1", | |
"del": "~0" | |
}, | |
"scripts": { | |
"default": "gulp" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Related issue: