What is the difference between PATHS and MAP properties of RequireJS

3

In theory it seems that the two configuration properties of RequireJS focus on the same action.

Does anyone know the differences in how both settings work?

PATHS:

require.config({
  paths: {
    'modulo': 'endereco/para/o/modulo'
  }
 });

MAP:

require.config({
  map: {
    '*': {modulo: 'endereco/para/o/modulo'}
  }
 });
    
asked by anonymous 28.02.2014 / 19:34

1 answer

2

According to documentation :

The paths property allows you to map modules that are to locations other than the URL base of the script.

One of the uses indicated in documentation is for fallback , that is, to allow the use of the script from a CDN in production and from a local URL for development.

And example is:

requirejs.config({
    //To get timely, correct error triggers in IE, force a define/shim exports check.
    enforceDefine: true,
    paths: {
        jquery: [
            'http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min',
            //If the CDN location fails, load from this location
            'lib/jquery'
        ]
    }
});

//Later
require(['jquery'], function ($) {
});

Use to set alternative locations for the same module.

On the other hand, the map property allows different scripts (modules) of the same project that require a third module to use different versions of that module.

Example:

requirejs.config({
    map: {
        'newmodule': {
            'foo': 'foo1.2'
        },
        'oldmodule': {
            'foo': 'foo1.0'
        }
    }
});

According to the above configuration, when newmodule uses require('foo') it will receive foo1.2.js . When oldmodule does the same, it will receive foo1.0.js .

Use to define which version of a particular module should be imported by each module.

    
28.02.2014 / 22:04