Skip to content

Instantly share code, notes, and snippets.

@aslansky
Created March 23, 2014 19:29
Show Gist options
  • Save aslansky/9728460 to your computer and use it in GitHub Desktop.
Save aslansky/9728460 to your computer and use it in GitHub Desktop.
// browserify
var browserify = require('browserify');
var es6ify = require('es6ify');
// gulp stuff
var gulp = require('gulp');
var livereload = require('gulp-livereload');
var source = require('vinyl-source-stream');
var jshint = require('gulp-jshint');
var livereload = require('gulp-livereload');
var watch = require('gulp-watch');
var uglify = require('gulp-uglify');
var streamify = require('gulp-streamify');
// stuff
var map = require('map-stream');
// static server
var http = require('http');
var ecstatic = require('ecstatic');
// error log for browserify
var errLog = function (err) {
if (err) {
gutil.log(err.toString());
}
};
// build scripts
gulp.task('scripts', function () {
return browserify('./src/js/main.js')
.transform(es6ify)
.bundle()
.pipe(source('main.js'))
.pipe(streamify(uglify()))
.pipe(gulp.dest('./dist/js'));
});
// watch scripts
gulp.task('watch-scripts', function () {
return gulp.src('./src/js/**/*.js')
.pipe(watch({name: 'JS'}))
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('default'))
.pipe(map(function () {
browserify('./src/js/main.js')
.transform(es6ify)
.bundle({debug: true}, errLog)
.pipe(source('main.js'))
.pipe(gulp.dest('./dist/js'))
.pipe(livereload());
}));
});
gulp.task('server', function () {
http.createServer(ecstatic({root: __dirname})).listen(8080);
gutil.log(gutil.colors.blue('HTTP server listening on port 8080'));
});
gulp.task('default', ['server', 'watch-scripts']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment