Reputation: 6512
I'm having a problem with r.js finding file dependencies on nested require calls.
If I pass require an array of strings, the compressor works fine and all the file dependancies are found.
define([
'jquery',
'underscore',
'backbone'
], function() {
require(['views/MobileNavView']); // Works fine!
});
If I pass require an array of strings I've assigned to a variable, the compressor doesn't find the file dependencies.
var requiredFiles = [
'views/MobileNavView'
];
define([
'jquery',
'underscore',
'backbone'
], function() {
require(requiredFiles); // Doesn't Work!
});
What could be causing the compressor to not find the file dependencies if I assign the array of strings to a variable?
Here is my app.build.js
({
baseUrl: '.',
findNestedDependencies: true,
mainConfigFile: 'Main.js',
name: 'Main',
out: 'Core.js',
optimize: 'none'
})
Upvotes: 2
Views: 549
Reputation: 13181
That's actually mentioned and explained on the r.js
docs page
(...) So, it will not find modules that are loaded via a variable name:
var mods = someCondition ? ['a', 'b'] : ['c', 'd']; require(mods);
That's because r.js
scans the scripts as text, it doesn't actually evaluate them. Take a look at its source code, you'll see there's a lot of regular expression matching going on.
Upvotes: 3