@@ -6,14 +6,14 @@ import stylish from 'gulp-jscs-stylish';
66import babel from 'gulp-babel' ;
77import rename from 'gulp-rename' ;
88
9- import browserify from 'browserify' ;
10- import buffer from 'vinyl-buffer' ;
11- import del from 'del' ;
12- import path from 'path' ;
9+ import browserify from 'browserify' ;
10+ import buffer from 'vinyl-buffer' ;
11+ import del from 'del' ;
12+ import path from 'path' ;
1313import { Promise } from 'es6-promise' ;
14- import source from 'vinyl-source-stream' ;
15- import sourcemaps from 'gulp-sourcemaps' ;
16- import uglify from 'gulp-uglify' ;
14+ import source from 'vinyl-source-stream' ;
15+ import sourcemaps from 'gulp-sourcemaps' ;
16+ import uglify from 'gulp-uglify' ;
1717
1818const ALL_SOURCES = [
1919 path . join ( __dirname , '/*.js' ) ,
@@ -37,51 +37,69 @@ gulp.task('clean', function() {
3737 return Promise . all ( [ del ( 'dist/' ) , del ( 'coverage/' ) ] ) ;
3838} ) ;
3939
40- const browserifyConfig = {
40+ gulp . task ( 'build' , [
41+ 'build:bundled:min' ,
42+ 'build:external:min' ,
43+ 'build:bundled:debug' ,
44+ 'build:external:debug' ,
45+ 'build:components'
46+ ] ) ;
47+
48+ const bundledConfig = {
4149 debug : true ,
42- entries : 'src/Github .js' ,
43- standalone : 'Github '
50+ entries : 'lib/GitHub .js' ,
51+ standalone : 'GitHub '
4452} ;
45- gulp . task ( 'build' , function ( ) {
46- browserify ( browserifyConfig )
47- . transform ( 'babelify' )
48- . bundle ( )
49- . pipe ( source ( 'Github.js' ) )
50- . pipe ( buffer ( ) )
51- . pipe ( sourcemaps . init ( {
52- loadMaps : true
53- } ) )
54- . pipe ( uglify ( ) )
55- . pipe ( rename ( {
56- extname : '.bundle.min.js'
57- } ) )
53+ const externalConfig = {
54+ debug : true ,
55+ entries : 'lib/GitHub.js' ,
56+ standalone : 'GitHub' ,
57+ external : [
58+ 'axios' ,
59+ 'js-base64' ,
60+ 'es6-promise' ,
61+ 'debug' ,
62+ 'utf8'
63+ ] ,
64+ bundleExternal : false
65+ } ;
66+ gulp . task ( 'build:bundled:min' , function ( ) {
67+ return buildBundle ( bundledConfig , '.bundle.min.js' , true ) ;
68+ } ) ;
69+ gulp . task ( 'build:external:min' , function ( ) {
70+ return buildBundle ( externalConfig , '.min.js' , true ) ;
71+ } ) ;
72+ gulp . task ( 'build:bundled:debug' , function ( ) {
73+ return buildBundle ( bundledConfig , '.bundle.js' , false ) ;
74+ } ) ;
75+ gulp . task ( 'build:external:debug' , function ( ) {
76+ return buildBundle ( externalConfig , '.js' , false ) ;
77+ } ) ;
78+ gulp . task ( 'build:components' , function ( ) {
79+ return gulp . src ( 'lib/*.js' )
80+ . pipe ( sourcemaps . init ( ) )
81+ . pipe ( babel ( ) )
5882 . pipe ( sourcemaps . write ( '.' ) )
59- . pipe ( gulp . dest ( 'dist' ) )
83+ . pipe ( gulp . dest ( 'dist/components ' ) )
6084 ;
85+ } ) ;
6186
62- browserify ( browserifyConfig )
87+ function buildBundle ( options , extname , minify ) {
88+ let stream = browserify ( options )
6389 . transform ( 'babelify' )
6490 . bundle ( )
65- . pipe ( source ( 'Github .js' ) )
91+ . pipe ( source ( 'GitHub .js' ) )
6692 . pipe ( buffer ( ) )
6793 . pipe ( sourcemaps . init ( {
6894 loadMaps : true
69- } ) )
70- . pipe ( rename ( {
71- extname : '.bundle.js'
72- } ) )
73- . pipe ( sourcemaps . write ( '.' ) )
74- . pipe ( gulp . dest ( 'dist' ) )
75- ;
95+ } ) ) ;
7696
77- return gulp . src ( 'src/*.js' )
78- . pipe ( babel ( ) )
79- . pipe ( sourcemaps . init ( ) )
97+ if ( minify ) {
98+ stream = stream . pipe ( uglify ( ) ) ;
99+ }
100+
101+ return stream . pipe ( rename ( { extname} ) )
80102 . pipe ( sourcemaps . write ( '.' ) )
81- . pipe ( gulp . dest ( 'dist/components ' ) )
103+ . pipe ( gulp . dest ( 'dist' ) )
82104 ;
83- } ) ;
84-
85- gulp . task ( 'default' , [ 'clean' ] , function ( ) {
86- gulp . start ( 'lint' , 'test:mocha' , 'build' ) ;
87- } ) ;
105+ }
0 commit comments