K
K
Konstantin Kitmanov2012-08-16 17:45:16
JavaScript
Konstantin Kitmanov, 2012-08-16 17:45:16

Why don't named RequireJS modules work?

I write a named module, like this:

define(
    'agent/app',
    [
        'agent/Router'
    ],
    function(Router) {
        console.log('app');
        new Router();
    }
);


The config is like this:
{
    urlArgs: 'bust=' +  (new Date()).getTime(),

    baseUrl: '/site_static/js',
    paths: {
        underscore: 'libs/underscore',
        backbone: 'libs/backbone',
        jquery: 'libs/jquery'
    },
    shim: {
        underscore: {exports: '_'},
        backbone: {exports: 'Backbone'},
        jquery: {exports: '$'}
    }
};


At the same time, if you comment out the name of the module, then everything works fine.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nur, 2012-08-16
@nur

The documentation says that it is better not to use named modules.
It is normally best to avoid coding in a name for the module and just let the optimization tool burn in the module names.
In our project, we map modules through the config, for one we get a bad DI control

paths: {
        underscore: 'libs/underscore',
        backbone: 'libs/backbone',
        jquery: 'libs/jquery',

        app : 'agent/app',
        router : 'app/router'
    },

and where needed
require('app');
require('router');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question