Skip to content

Instantly share code, notes, and snippets.

@lishiyo
Last active August 29, 2015 14:18
Show Gist options
  • Save lishiyo/250415233a462654ccae to your computer and use it in GitHub Desktop.
Save lishiyo/250415233a462654ccae to your computer and use it in GitHub Desktop.
Gulpfile Boilerplate - Browserify, Mocha, Phantom
// Gulp Dependencies
var gulp = require('gulp');
var rename = require('gulp-rename');
// Build Dependencies
var browserify = require('gulp-browserify');
var uglify = require('gulp-uglify');
// Style Dependencies
var sass = require('gulp-sass');
var prefix = require('gulp-autoprefixer');
var minifyCSS = require('gulp-minify-css');
// Development Dependencies
var jshint = require('gulp-jshint');
// Test Dependencies
var mochaPhantomjs = require('gulp-mocha-phantomjs');
/** TESTING **/
gulp.task('lint-client', function() {
return gulp.src('./client/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
gulp.task('lint-test', function() {
return gulp.src('./test/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
gulp.task('browserify-client', ['lint-client'], function() {
return gulp.src('./client/tabs.js')
.pipe(browserify({
insertGlobals: true
}))
.pipe(rename('tabs.js'))
.pipe(gulp.dest('build'))
.pipe(gulp.dest('public/javascripts'));
});
gulp.task('browserify-test', ['lint-test'], function() {
return gulp.src('test/tabs.js')
.pipe(browserify({
insertGlobals: true
}))
.pipe(rename('tabs-test.js'))
.pipe(gulp.dest('build'));
});
gulp.task('test', ['lint-test', 'browserify-test'], function() {
return gulp.src('test/index.html')
.pipe(mochaPhantomjs());
});
/** if Client JS changes, re-browserify client and then re-lint and re-browserify Test **/
gulp.task('watch', function() {
gulp.watch('client/**/*.js', ['browserify-client', 'test']);
gulp.watch('test/**/*.js', ['test']);
});
/** Building to Public **/
gulp.task('styles', function() {
return gulp.src('client/tabs.scss')
.pipe(sass())
.pipe(prefix({ cascade: true }))
.pipe(rename('tabs.css'))
.pipe(gulp.dest('build'))
.pipe(gulp.dest('public/stylesheets'));
});
gulp.task('minify', ['styles'], function() {
return gulp.src('build/tabs.css')
.pipe(minifyCSS())
.pipe(rename('tabs.min.css'))
.pipe(gulp.dest('public/stylesheets'));
});
gulp.task('uglify', ['browserify-client'], function() {
return gulp.src('build/tabs.js')
.pipe(uglify())
.pipe(rename('tabs.min.js'))
.pipe(gulp.dest('public/javascripts'));
});
gulp.task('build', ['uglify', 'minify']);
/** use in development **/
gulp.task("watch-dev", function(){
gulp.watch('client/*.js', ['browserify-client']);
gulp.watch('client/*.scss', ['styles']);
});
// Default Workflow
// TEST does the lintering and browserifying
gulp.task('default', ['test', 'build', 'watch']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment