What is the best way to enable jQuery, Underscore, and Backbone as AMD modules using require.js?

I have seen many options for loading modules that do not yet support AMD , and I would like to know what is the best practice.

In the end, I would like to write such modules:

module.js: define(["jQuery", "Underscore", "Backbone"], function($, _, Backbone) { ... module code here } 

But there are many problems loading these dependencies using AMD, as they are not all compatible with AMD.

+6
source share
5 answers

I created a todo-list web-based tabular application that loads all modules as AMD modules (without loaders).

Check this:

https://github.com/ronreiter/webapp-boilerplate

+4
source

Thomas Davis has a better example (imo) for loading jquery / underscore / backbone in his not updated example. Start by viewing the bootloader here.

It uses the RequireJS ordering plugin found here to load modules synchronously.

+2
source

Take a look at this example. It shows well how to use a support framework with requirejs. It also shows how you can organize your model, view, and collections neatly.

+1
source

The latest version of RequireJS adds the ability to use JS files NON-AMD.

 require.config({ 'paths': { "underscore": "libs/underscore-min", "backbone": "libs/backbone-min" }, 'shim': { backbone: { 'deps': ['jquery', 'underscore'], 'exports': 'Backbone' } } }); 

Give it a try.

+1
source

One thing that I don’t understand about AMD is that it downloads the necessary js only when necessary, but with a demo application it downloads all js html css files when accessing the application to load the first page.

0
source

Source: https://habr.com/ru/post/904480/


All Articles