Skip to content

Instantly share code, notes, and snippets.

@mikemunsie
Created July 24, 2014 03:53
Show Gist options
  • Save mikemunsie/4e8e25fab66ffc731033 to your computer and use it in GitHub Desktop.
Save mikemunsie/4e8e25fab66ffc731033 to your computer and use it in GitHub Desktop.
Sample Gulp File (Coffee, SASS, Concat, Uglify)
var gulp = require('gulp');
var coffee = require('gulp-coffee');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var compass = require('gulp-compass');
var path = require('path');
var config = {
jsExt: {
files: "js-ext/**/*",
},
sass: {
files: "sass/**/*",
dest: "css",
compass: {
bundle_exec: true,
style: "compressed",
css: "css",
sass: "sass",
project: path.join(__dirname),
comments: false
}
},
coffee: {
files: "coffee/**/*",
dest: "js"
},
uglify: {
files: "js/**/*",
dest: "js-min"
},
concat: {
files: "js/**/*",
dest: "js-min",
prefix: "package-",
packages: {
"beans": [
"js-ext/ext1.js",
"js-min/coolBeans.js",
"js-min/coolBeans2.js"
],
"test1": [
"js-min/test.js",
"js-min/test2.js"
]
}
}
};
// Compass good to go
gulp.task('compass', function(){
return gulp.src(config.sass.files)
.pipe(compass(config.sass.compass));
});
// Coffee good to go
gulp.task('coffee', function(){
return gulp.src(config.coffee.files)
.pipe(coffee())
.pipe(gulp.dest(config.coffee.dest));
});
// Uglify good to go
gulp.task('uglify', ['coffee'], function(){
return gulp.src(config.uglify.files)
.pipe(uglify())
.pipe(gulp.dest(config.uglify.dest));
});
// Concat ready to go
gulp.task('concat', ['coffee', 'uglify'], function(){
var fileName = "";
Object.keys(config.concat.packages).forEach(function(key) {
fileName = config.concat.prefix + key + ".js";
gulp.src(config.concat.packages[key])
.pipe(concat(fileName))
.pipe(gulp.dest(config.uglify.dest));
});
});
// Rerun the task when a file changes
gulp.task('watch', function() {
gulp.watch(config.coffee.files, ['coffee', 'uglify', 'concat']);
gulp.watch(config.jsExt.files, ['concat']);
gulp.watch(config.sass.files, ['compass']);
});
// The default task (called when you run `gulp` from cli)
gulp.task('default', ['coffee', 'uglify', 'concat', 'compass', 'watch']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment