0

I use r.js optimizer to bundle my project.

In some places, I must load files synchronously like here:

define('module-name', ['adal-angular'], function () {
    var app = angular.module('myApp', ['AdalAngular']);

In the require.config.js I have this:

paths: {
        adal: 'bower_components/adal-angular/dist/adal.min',
        'adal-angular': 'bower_components/adal-angular/dist/adal-angular.min',
}

and Shim:

shim: {
      'adal-angular': ['angular', 'adal'],
}

My optimize configuration contains: findNestedDependencies: true, Yet adal and adal-angular are not included in the bundled file, unless I add this line somewhere in my code: require("adal-angular") - which is redundant and I would like not to do that.

7
  • 1
    "I must load files synchronously like here:". RequireJS definitely loads any modules loaded in that snippet asynchronously. Actually, let me add this: in a browser RequireJS never loads anything sychronously.
    – Louis
    May 22, 2016 at 12:03
  • The difference between loading adal-angular in an array at the definition of the module, than loading it by executing require('adal-angular') is that the function is not executed until it's loaded in the first option.
    – johni
    May 22, 2016 at 12:04
  • In both cases the module is loaded asynchronously.
    – Louis
    May 22, 2016 at 12:06
  • Ok, maybe the term is not right. In the first case, the function's executing is delayed until the dependencies are loaded (those mentioned in the array). In the second case it's not.
    – johni
    May 22, 2016 at 12:07
  • If by "function" you mean the module's factory function, then you are mistaken. A require([...], cb) call will load the dependencies in the array at the time of the call, but a require(string) call will load the dependencies before the factory function is called because RequireJS scans the code of the module and changes the dependency array itself. I cannot give a detailed explanation in a comment but see this answer for the details.
    – Louis
    May 22, 2016 at 12:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.