Skip to content

Commit 9e86e69

Browse files
committed
And standalone bundles for legacy javascript usage
1 parent d8bd174 commit 9e86e69

11 files changed

+61
-171
lines changed

gulpfile.js

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ var sources = {
3030

3131
// Standalone application to create vendor bundles for. These can be imported
3232
// 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+
};
3440

3541
// Build application call, wraps building entry point files for a single
3642
// application. This is called by build and dev tasks.
@@ -83,7 +89,7 @@ function browserify_stream (file, config, cb_output) {
8389
bower_resolve.init(function () {
8490
var bundle_stream = browserify();
8591

86-
standalone.map(function (module) {
92+
Object.keys(standalone).map(function (module) {
8793
bundle_stream = bundle_stream.external(module);
8894
});
8995

@@ -98,7 +104,7 @@ function browserify_stream (file, config, cb_output) {
98104
}
99105

100106
bundle_stream
101-
.transform('debowerify', {ignoreModules: standalone})
107+
.transform('debowerify', {ignoreModules: Object.keys(standalone)})
102108
.bundle()
103109
.on('error', function (ev) {
104110
gulp_util.beep();
@@ -115,14 +121,40 @@ function browserify_stream (file, config, cb_output) {
115121
function build_vendor_sources(data, cb_output) {
116122
bower_resolve.offline = true;
117123
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()
120131
.require(bower_resolve(module), {expose: module})
121132
.bundle()
122133
.pipe(vinyl_source(module + '.js'))
123134
.pipe(vinyl_buffer())
124135
.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);
126158
});
127159

128160
es

media/javascript/jquery/jquery-2.0.3.min.js

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../static/vendor/jquery-standalone.js

media/javascript/jquery/jquery-2.0.3.min.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

media/javascript/jquery/jquery-migrate-1.2.1.min.js

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../static/vendor/jquery-migrate-standalone.js

0 commit comments

Comments
 (0)