Skip to content

Instantly share code, notes, and snippets.

@ksmithbaylor
Created July 24, 2015 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ksmithbaylor/e28e0a3563dc77d99106 to your computer and use it in GitHub Desktop.
Save ksmithbaylor/e28e0a3563dc77d99106 to your computer and use it in GitHub Desktop.
var gulp = require('gulp');
var browserify = require('browserify');
var watchify = require('watchify');
var babelify = require('babelify');
var uglifyify = require('uglifyify');
var source = require('vinyl-source-stream');
var chalk = require('chalk');
var inputDir = './src/';
var outputDir = './dist/';
var paths = {
input: {
js: inputDir + '**/*.js',
jsEntry: inputDir + 'app.js',
sass: inputDir + 'style/recommendations.scss',
html: inputDir + 'index.html'
},
output: {
css: outputDir + 'recommendations.css'
}
};
function buildJS(shouldWatch, done) {
var bundle = function (b, done) {
console.log(chalk.blue('(re)bundling js'));
b.transform(babelify);
b.transform({global: true}, 'uglifyify');
b.bundle()
.on('error', function(err) {
console.log(chalk.red(err.message));
this.emit('end');
})
.pipe(source('recommendations.js'))
.pipe(gulp.dest(outputDir))
.on('end', done || function(){});
};
var b = shouldWatch ?
watchify(browserify(watchify.args)) :
browserify({
builtins: []
});
b.on('update', function() { bundle(b); });
b.add(paths.input.jsEntry);
bundle(b, done);
}
gulp.task('watch-js', function (done) {
buildJS(true, done);
});
gulp.task('build-js', function (done) {
buildJS(false, done);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment