Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

Commit 9b89d79

Browse files
committed
Change module optimization to be whole project rather than per-module
Credit @orourkedd. Fixes #164.
1 parent f168b56 commit 9b89d79

File tree

2 files changed

+4
-34
lines changed

2 files changed

+4
-34
lines changed

lib/requirejs/rails/config.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,6 @@ def module_name_for(mod)
142142
end
143143
end
144144

145-
def module_path_for(mod)
146-
self.target_dir+(module_name_for(mod)+'.js')
147-
end
148-
149145
def get_binding
150146
return binding()
151147
end

lib/requirejs/rails/rjs_driver.js.erb

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,16 @@ var requirejs = require('<%= rjs_path %>'),
55
baseConfig = <%=
66
modifiedHash = build_config.select {|k, _| k != "modules"}
77
pathsHash = modifiedHash["paths"]
8+
modifiedHash["dir"] = self.target_dir
89
modifiedHash["paths"] = pathsHash.select {|_, v| !v.is_a?(Array)} if !pathsHash.nil?
910

1011
JSON.pretty_generate(modifiedHash)
1112
%>;
1213

13-
// Function used to mix in baseConfig to a new config target
14-
function mix(target) {
15-
for (var prop in baseConfig) {
16-
if (baseConfig.hasOwnProperty(prop)) {
17-
target[prop] = baseConfig[prop];
18-
}
19-
}
20-
return target;
21-
}
22-
23-
var module_specs = [
14+
baseConfig.modules = [
2415
<% build_config['modules'].each do |m| %>
25-
<%= JSON.pretty_generate(m.merge 'out' => module_path_for(m).to_s ) %>,
16+
<%= JSON.pretty_generate(m) %>,
2617
<% end %>
2718
];
2819

29-
// Error handler invoked in case requirejs compilation fails
30-
var errback = function(error) {
31-
process.stderr.write(error.toString());
32-
process.exit(1);
33-
}
34-
35-
// Do a series of builds of individual files, using the args suggested by:
36-
// http://requirejs.org/docs/optimization.html#onejs
37-
//
38-
// r.js will eventually need a nested call idiom to handle async
39-
// builds. Anticipating that need.
40-
var async_runner = module_specs.reduceRight(function(prev, curr) {
41-
return function (buildReportText) {
42-
requirejs.optimize(mix(curr), prev, errback);
43-
};
44-
}, function(buildReportText) {} );
45-
46-
async_runner();
20+
requirejs.optimize(baseConfig);

0 commit comments

Comments
 (0)