From ea8c0dab42ee51177dbd5dd23834285635f629bc Mon Sep 17 00:00:00 2001 From: Jake Marsh Date: Mon, 28 Mar 2016 21:41:02 -0700 Subject: [PATCH 1/3] code cleanup, es6 conversion --- gulp/tasks/browserify.js | 18 ++++++++---------- gulp/util/bundleLogger.js | 17 ++++++----------- gulp/util/handleErrors.js | 7 ++++--- 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/gulp/tasks/browserify.js b/gulp/tasks/browserify.js index 369ba00f..392c2f8c 100644 --- a/gulp/tasks/browserify.js +++ b/gulp/tasks/browserify.js @@ -1,6 +1,5 @@ 'use strict'; -import config from '../config'; import gulp from 'gulp'; import gulpif from 'gulp-if'; import gutil from 'gulp-util'; @@ -12,21 +11,20 @@ import watchify from 'watchify'; import browserify from 'browserify'; import babelify from 'babelify'; import uglify from 'gulp-uglify'; -import handleErrors from '../util/handleErrors'; import browserSync from 'browser-sync'; import debowerify from 'debowerify'; import ngAnnotate from 'browserify-ngannotate'; - -function createSourcemap() { - return !global.isProd || config.browserify.prodSourcemap; -} +import handleErrors from '../util/handleErrors'; +import config from '../config'; // Based on: http://blog.avisi.nl/2014/04/25/how-to-keep-a-fast-build-with-browserify-and-reactjs/ function buildScript(file) { + const shouldCreateSourcemap = !global.isProd || config.browserify.prodSourcemap; + let bundler = browserify({ entries: [config.sourceDir + 'js/' + file], - debug: createSourcemap(), + debug: shouldCreateSourcemap, cache: {}, packageCache: {}, fullPaths: !global.isProd @@ -59,12 +57,12 @@ function buildScript(file) { return stream.on('error', handleErrors) .pipe(source(file)) - .pipe(gulpif(createSourcemap(), buffer())) - .pipe(gulpif(createSourcemap(), sourcemaps.init({ loadMaps: true }))) + .pipe(gulpif(shouldCreateSourcemap, buffer())) + .pipe(gulpif(shouldCreateSourcemap, sourcemaps.init({ loadMaps: true }))) .pipe(gulpif(global.isProd, streamify(uglify({ compress: { drop_console: true } // eslint-disable-line camelcase })))) - .pipe(gulpif(createSourcemap(), sourcemaps.write(sourceMapLocation))) + .pipe(gulpif(shouldCreateSourcemap, sourcemaps.write(sourceMapLocation))) .pipe(gulp.dest(config.scripts.dest)) .pipe(browserSync.stream()); } diff --git a/gulp/util/bundleLogger.js b/gulp/util/bundleLogger.js index 8f8fbaf5..c1d8c5cf 100644 --- a/gulp/util/bundleLogger.js +++ b/gulp/util/bundleLogger.js @@ -1,26 +1,21 @@ 'use strict'; -/* bundleLogger - * ------------ - * Provides gulp style logs to the bundle method in browserify.js - */ - import gutil from 'gulp-util'; import prettyHrtime from 'pretty-hrtime'; -var startTime; +let startTime; export default { start() { startTime = process.hrtime(); - gutil.log('Running', gutil.colors.green('\'bundle\'') + '...'); + gutil.log(`${gutil.colors.green('Rebundling')}...`); }, end() { - var taskTime = process.hrtime(startTime); - var prettyTime = prettyHrtime(taskTime); - gutil.log('Finished', gutil.colors.green('\'bundle\''), 'in', gutil.colors.magenta(prettyTime)); + const taskTime = process.hrtime(startTime); + const prettyTime = prettyHrtime(taskTime); + gutil.log(`Finished ${gutil.colors.green('rebundling')} in ${gutil.colors.magenta(prettyTime)}`); } -}; \ No newline at end of file +}; diff --git a/gulp/util/handleErrors.js b/gulp/util/handleErrors.js index 77dca45f..04d8b68f 100644 --- a/gulp/util/handleErrors.js +++ b/gulp/util/handleErrors.js @@ -1,12 +1,13 @@ 'use strict'; +import gutil from 'gulp-util'; import notify from 'gulp-notify'; export default function(error) { if( !global.isProd ) { - var args = Array.prototype.slice.call(arguments); + const args = Array.prototype.slice.call(arguments); // Send error to notification center with gulp-notify notify.onError({ @@ -20,8 +21,8 @@ export default function(error) { } else { // Log the error and stop the process // to prevent broken code from building - console.log(error); + gutil.log(gutil.colors.red(error)); process.exit(1); } -}; \ No newline at end of file +}; From 9e0eca49a5537f7af8213b3a75a83c9eb448058f Mon Sep 17 00:00:00 2001 From: Jake Marsh Date: Mon, 28 Mar 2016 21:41:08 -0700 Subject: [PATCH 2/3] use bundleLogger --- gulp/tasks/browserify.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/gulp/tasks/browserify.js b/gulp/tasks/browserify.js index 392c2f8c..3582ff3d 100644 --- a/gulp/tasks/browserify.js +++ b/gulp/tasks/browserify.js @@ -2,7 +2,6 @@ import gulp from 'gulp'; import gulpif from 'gulp-if'; -import gutil from 'gulp-util'; import source from 'vinyl-source-stream'; import sourcemaps from 'gulp-sourcemaps'; import buffer from 'vinyl-buffer'; @@ -15,6 +14,7 @@ import browserSync from 'browser-sync'; import debowerify from 'debowerify'; import ngAnnotate from 'browserify-ngannotate'; import handleErrors from '../util/handleErrors'; +import bundleLogger from '../util/bundleLogger'; import config from '../config'; // Based on: http://blog.avisi.nl/2014/04/25/how-to-keep-a-fast-build-with-browserify-and-reactjs/ @@ -33,10 +33,7 @@ function buildScript(file) { if ( !global.isProd ) { bundler = watchify(bundler); - bundler.on('update', function() { - rebundle(); - gutil.log('Rebundle...'); - }); + bundler.on('update', rebundle); } const transforms = [ @@ -52,10 +49,14 @@ function buildScript(file) { }); function rebundle() { + bundleLogger.start(); + const stream = bundler.bundle(); const sourceMapLocation = global.isProd ? './' : ''; - return stream.on('error', handleErrors) + return stream + .on('error', handleErrors) + .on('end', bundleLogger.end) .pipe(source(file)) .pipe(gulpif(shouldCreateSourcemap, buffer())) .pipe(gulpif(shouldCreateSourcemap, sourcemaps.init({ loadMaps: true }))) From 41acb4316ad28f47cfe160d87c2266c75f21be6f Mon Sep 17 00:00:00 2001 From: Jake Marsh Date: Mon, 28 Mar 2016 21:45:59 -0700 Subject: [PATCH 3/3] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b131d9ba..e7d68ec1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angularjs-gulp-browserify-boilerplate", - "version": "1.5.7", + "version": "1.5.8", "author": "Jake Marsh ", "description": "Boilerplate using AngularJS, SASS, Gulp, and Browserify while also utilizing best practices.", "repository": {