UNPKG

code-challenge-7geese

Version:

This is a revised solution for the 7Geese JavaScript Challenge.

49 lines (45 loc) 1.79 kB
/*global require, pipe*/ 'use strict'; var assign = require('lodash.assign'), buffer = require('vinyl-buffer'), browserify = require('browserify'), filesize = require('gulp-filesize'), gulp = require('gulp'), gutil = require('gulp-util'), rename = require('gulp-rename'), source = require('vinyl-source-stream'), sourcemaps = require('gulp-sourcemaps'), uglify = require('gulp-uglify'), watchify = require('watchify'); var customOpts = { entries: ['./src/main.js'], standalone: 'sGeese', debug: true }, opts = assign({}, watchify.args, customOpts), b = watchify(browserify(opts)); gulp.task('js', bundle); // so you can run `gulp js` to build the file b.on('update', bundle); // on any dep update, runs the bundler b.on('log', gutil.log); // output build logs to terminal function bundle() { return b.bundle() // log errors if they happen .on('error', gutil.log.bind(gutil, 'Browserify Error')) .pipe(source('sGeese.js')) // optional, remove if you don't need to buffer file contents .pipe(buffer()) // optional, remove if you dont want sourcemaps .pipe(sourcemaps.init({loadMaps: true})) // loads map from browserify file // Add transformation tasks to the pipeline here. .pipe(sourcemaps.write('./')) // writes .map file .pipe(gulp.dest('./www/js')); } gulp.task('min', function() { return gulp.src('./www/js/sGeese.js') .pipe(filesize()) .pipe(uglify()) .pipe(rename('sGeese.min.js')) .pipe(gulp.dest('./www/js')) .pipe(filesize()) .on('error', gutil.log); });