0
votes

When defining a module in require.js, I have to always list the common libs as dependencies:

define(['jquery', 'underscore', 'backbone'], function(){
   //do stuff here
});

Is there a way that I don't have to always require these common modules in every define and just require them once, or does this ruin the whole concept of independent modules?

2

2 Answers

3
votes

Pretty much the latter: one of the main purposes of using a module system is to avoid the need for separate pieces of code to interface with each other through globals. That pretty much requires dependencies to be explicitly called out in each module and given locally-scoped names.

0
votes

Take a look at the https://github.com/requirejs/example-multipage application. It uses a mix of page-specific and common modules, according to the readme file.