11'use strict' ;
22
3- import config from '../config' ;
43import gulp from 'gulp' ;
54import gulpif from 'gulp-if' ;
6- import gutil from 'gulp-util' ;
75import source from 'vinyl-source-stream' ;
86import sourcemaps from 'gulp-sourcemaps' ;
97import buffer from 'vinyl-buffer' ;
@@ -12,21 +10,21 @@ import watchify from 'watchify';
1210import browserify from 'browserify' ;
1311import babelify from 'babelify' ;
1412import uglify from 'gulp-uglify' ;
15- import handleErrors from '../util/handleErrors' ;
1613import browserSync from 'browser-sync' ;
1714import debowerify from 'debowerify' ;
1815import ngAnnotate from 'browserify-ngannotate' ;
19-
20- function createSourcemap ( ) {
21- return ! global . isProd || config . browserify . prodSourcemap ;
22- }
16+ import handleErrors from '../util/handleErrors' ;
17+ import bundleLogger from '../util/bundleLogger' ;
18+ import config from '../config' ;
2319
2420// Based on: http://blog.avisi.nl/2014/04/25/how-to-keep-a-fast-build-with-browserify-and-reactjs/
2521function buildScript ( file ) {
2622
23+ const shouldCreateSourcemap = ! global . isProd || config . browserify . prodSourcemap ;
24+
2725 let bundler = browserify ( {
2826 entries : [ config . sourceDir + 'js/' + file ] ,
29- debug : createSourcemap ( ) ,
27+ debug : shouldCreateSourcemap ,
3028 cache : { } ,
3129 packageCache : { } ,
3230 fullPaths : ! global . isProd
@@ -35,10 +33,7 @@ function buildScript(file) {
3533 if ( ! global . isProd ) {
3634 bundler = watchify ( bundler ) ;
3735
38- bundler . on ( 'update' , function ( ) {
39- rebundle ( ) ;
40- gutil . log ( 'Rebundle...' ) ;
41- } ) ;
36+ bundler . on ( 'update' , rebundle ) ;
4237 }
4338
4439 const transforms = [
@@ -54,17 +49,21 @@ function buildScript(file) {
5449 } ) ;
5550
5651 function rebundle ( ) {
52+ bundleLogger . start ( ) ;
53+
5754 const stream = bundler . bundle ( ) ;
5855 const sourceMapLocation = global . isProd ? './' : '' ;
5956
60- return stream . on ( 'error' , handleErrors )
57+ return stream
58+ . on ( 'error' , handleErrors )
59+ . on ( 'end' , bundleLogger . end )
6160 . pipe ( source ( file ) )
62- . pipe ( gulpif ( createSourcemap ( ) , buffer ( ) ) )
63- . pipe ( gulpif ( createSourcemap ( ) , sourcemaps . init ( { loadMaps : true } ) ) )
61+ . pipe ( gulpif ( shouldCreateSourcemap , buffer ( ) ) )
62+ . pipe ( gulpif ( shouldCreateSourcemap , sourcemaps . init ( { loadMaps : true } ) ) )
6463 . pipe ( gulpif ( global . isProd , streamify ( uglify ( {
6564 compress : { drop_console : true } // eslint-disable-line camelcase
6665 } ) ) ) )
67- . pipe ( gulpif ( createSourcemap ( ) , sourcemaps . write ( sourceMapLocation ) ) )
66+ . pipe ( gulpif ( shouldCreateSourcemap , sourcemaps . write ( sourceMapLocation ) ) )
6867 . pipe ( gulp . dest ( config . scripts . dest ) )
6968 . pipe ( browserSync . stream ( ) ) ;
7069 }
0 commit comments