Skip to content

Commit 26f27dd

Browse files
committed
Prefix application bundles with application name
This will allow `projects/js/tools.js` to be imported with `require('projects/tools')`
1 parent 1be1b75 commit 26f27dd

File tree

13 files changed

+35
-24
lines changed

13 files changed

+35
-24
lines changed

gulpfile.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var gulp = require('gulp'),
1919
var sources = {
2020
builds: {'js/detail.js': {}},
2121
core: {
22-
'js/readthedocs-doc-embed.js': {create_module: false},
22+
'js/readthedocs-doc-embed.js': {expose: false},
2323
'js/autocomplete.js': {},
2424
'js/projectimport.js': {},
2525
},
@@ -53,7 +53,19 @@ function build_app_sources (application, minify) {
5353
bundle = gulp
5454
.src(bundle_path)
5555
.pipe(es.map(function (file, cb) {
56-
return browserify_stream(file, bundle_config, cb);
56+
if (typeof(bundle_config.expose) == 'undefined') {
57+
var parts = [
58+
application,
59+
path.basename(file.path, '.js')
60+
];
61+
bundle_config.expose = parts.join('/');
62+
}
63+
else if (bundle_config.expose === false) {
64+
bundle_config.expose = undefined;
65+
}
66+
return browserify_stream(
67+
file, bundle_config, cb
68+
);
5769
}));
5870

5971
if (minify) {
@@ -93,14 +105,13 @@ function browserify_stream (file, config, cb_output) {
93105
bundle_stream = bundle_stream.external(module);
94106
});
95107

96-
if (config.create_module === false) {
97-
bundle_stream.add(file.path)
108+
if (typeof(config.expose) == 'undefined') {
109+
bundle_stream.add(file.path);
98110
}
99111
else {
100-
var module_name = config.expose || path.basename(file.path, '.js');
101112
bundle_stream = bundle_stream.require(
102-
file.path,
103-
{expose: module_name})
113+
file.path, {expose: config.expose}
114+
);
104115
}
105116

106117
bundle_stream

readthedocs/builds/static/builds/js/detail.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readthedocs/core/static/core/js/autocomplete.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readthedocs/core/static/core/js/projectimport.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)