Skip to content

Instantly share code, notes, and snippets.

@jshbrntt
Created May 12, 2014 19:53
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jshbrntt/08b726b7dce29f685356 to your computer and use it in GitHub Desktop.
Save jshbrntt/08b726b7dce29f685356 to your computer and use it in GitHub Desktop.
Gulp + Watchify + Debowerify + Uglify
/* global require */
var gulp = require('gulp');
var browserify = require('browserify');
var sync = require('browser-sync');
var source = require('vinyl-source-stream');
var uglify = require('gulp-uglify');
var plumber = require('gulp-plumber');
var streamify = require('gulp-streamify');
var watchify = require('watchify');
gulp.task('sync', ['scripts'], function() {
sync.init(null, {
server: {
baseDir: "./www"
}
});
});
gulp.task('scripts', function () {
var bundler = watchify('./src/scripts/main');
bundler.transform('debowerify');
bundler.on('update', rebundle);
function rebundle () {
return bundler.bundle()
.pipe(source('bundle.js'))
.pipe(streamify(uglify()))
.pipe(gulp.dest('www/scripts'))
.pipe(sync.reload({stream:true, once: true}));
}
return rebundle();
});
gulp.task('default', ['sync'], function () {
gulp.watch("./src/scripts/**/*.js", ['scripts']);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment