@@ -30,7 +30,13 @@ var sources = {
30
30
31
31
// Standalone application to create vendor bundles for. These can be imported
32
32
// with require in the browser or with Node during testing.
33
- var standalone = [ 'jquery' , 'knockout' , 'jquery-migrate' , 'jquery-ui' ] ;
33
+ var standalone = {
34
+ 'jquery' : { standalone : 'jquery' } ,
35
+ 'knockout' : { } ,
36
+ 'jquery-migrate' : { standalone : 'jquery-migrate' } ,
37
+ 'jquery-ui' : { standalone : 'jquery-ui' } ,
38
+ 'underscore' : { standalone : '_' }
39
+ } ;
34
40
35
41
// Build application call, wraps building entry point files for a single
36
42
// application. This is called by build and dev tasks.
@@ -83,7 +89,7 @@ function browserify_stream (file, config, cb_output) {
83
89
bower_resolve . init ( function ( ) {
84
90
var bundle_stream = browserify ( ) ;
85
91
86
- standalone . map ( function ( module ) {
92
+ Object . keys ( standalone ) . map ( function ( module ) {
87
93
bundle_stream = bundle_stream . external ( module ) ;
88
94
} ) ;
89
95
@@ -98,7 +104,7 @@ function browserify_stream (file, config, cb_output) {
98
104
}
99
105
100
106
bundle_stream
101
- . transform ( 'debowerify' , { ignoreModules : standalone } )
107
+ . transform ( 'debowerify' , { ignoreModules : Object . keys ( standalone ) } )
102
108
. bundle ( )
103
109
. on ( 'error' , function ( ev ) {
104
110
gulp_util . beep ( ) ;
@@ -115,14 +121,40 @@ function browserify_stream (file, config, cb_output) {
115
121
function build_vendor_sources ( data , cb_output ) {
116
122
bower_resolve . offline = true ;
117
123
bower_resolve . init ( function ( ) {
118
- var standalone_modules = standalone . map ( function ( module ) {
119
- return browserify ( )
124
+ var standalone_modules = Object . keys ( standalone ) . map ( function ( module ) {
125
+ var vendor_options = standalone [ module ] || { } ,
126
+ vendor_bundles = [ ] ;
127
+
128
+ // Bundle vendor libs for import via require()
129
+ vendor_bundles . push (
130
+ browserify ( )
120
131
. require ( bower_resolve ( module ) , { expose : module } )
121
132
. bundle ( )
122
133
. pipe ( vinyl_source ( module + '.js' ) )
123
134
. pipe ( vinyl_buffer ( ) )
124
135
. pipe ( uglify ( ) )
125
- . pipe ( gulp . dest ( path . join ( pkg_config . name , 'static' , 'vendor' ) ) ) ;
136
+ . pipe ( gulp . dest (
137
+ path . join ( pkg_config . name , 'static' , 'vendor' )
138
+ ) )
139
+ ) ;
140
+
141
+ // Bundle standalone for legacy use. These should only be used on
142
+ // old documentation that does not yet use the new bundles
143
+ if ( typeof ( vendor_options . standalone ) != 'undefined' ) {
144
+ vendor_bundles . push (
145
+ browserify ( { standalone : vendor_options . standalone } )
146
+ . require ( bower_resolve ( module ) )
147
+ . bundle ( )
148
+ . pipe ( vinyl_source ( module + '-standalone.js' ) )
149
+ . pipe ( vinyl_buffer ( ) )
150
+ . pipe ( uglify ( ) )
151
+ . pipe ( gulp . dest (
152
+ path . join ( pkg_config . name , 'static' , 'vendor' )
153
+ ) )
154
+ ) ;
155
+ }
156
+
157
+ return es . merge ( vendor_bundles ) ;
126
158
} ) ;
127
159
128
160
es
0 commit comments