Mojimi
Mojimi

Reputation: 3171

How to chain dependencies in an AMD declared Dojo module?

I don't understand how can I chain loader calls when I'm defining a module, since define requires a return but itself does not return anything so I'm not sure what to do.

define([
  'require',
  'https://code.jquery.com/jquery-3.3.1.min.js',
],
function (require) {
  //Should I use a require or define...? I don't understand, none works
  return define([
    'https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.bundle.min.js'
  ],
  function() {
    const myModule = {...};
    return myModule;
  })
});

The reason I had to do the above is because I need to load jquery before loading bootstrap, since the AMD loader is asynchronous and Bootstrap requires jquery to be already loaded.

Upvotes: 0

Views: 170

Answers (1)

Akrion
Akrion

Reputation: 18525

You could use the config options of requirejs. Not familiar with dojo but usually what you would do is something like this:

require.config({
    paths: {
      'jquery': 'pathTo/jquery.min',
      'bootstrap': 'pathTo/bootstrap.min'
    }, 
    shim: {
      'bootstrap': { deps: ['jquery'] }
    }
})

More on require config here

Upvotes: 1

Related Questions