3

What is the difference between map vs path when building a theme / module?

Which are the restrictions?

var config = {

 map: {
    '*': {
        'jqueryjs': 'India_Newtheme/js/jquery',
        'bootstrapmin': 'India_Newtheme/js/vendor/bootstrap.min'
    }
  },
  paths: {            
      'jqueryjs': 'India_Newtheme/js/jquery',
      'bootstrapmin': 'India_Newtheme/js/vendor/bootstrap.min'
  }
};
3

Both does the same thing, while a map has an additional advantage to create an alias for entire Magento or a specific module.

Path does not have that advantage. It will consider for the entire Magento.

In your code,

var config = {
    map: {
        '*': {
            'jqueryjs': 'India_Newtheme/js/jquery',
            'bootstrapmin': 'India_Newtheme/js/vendor/bootstrap.min'
        },
        'MyVendor_MyModule': {
            'jqueryjs': 'MyVendor_MyModule/js/jquery',
        }
    },
    paths: {            
        'jqueryjs': 'India_Newtheme/js/jquery',
        'bootstrapmin': 'India_Newtheme/js/vendor/bootstrap.min'
    }
};

If you are defining something in "*" within map, it will consider for entire Magento, but if the same thing you define within some module name, in our case MyVendor_MyModule whenever the same alias jquery will be called within your module js file, it will call MyVendor_MyModule/js/jquery instead of India_Newtheme/js/jquery.

Hope this helps.

| improve this answer | |
0

map can be scoped to specific modules whereas paths cannot be. Also, map resolves only full module names, whereas paths can be used for URLs, partial directory paths, etc.

More information can be found in the new DevDocs documentation for RequireJS config: https://devdocs.magento.com/guides/v2.3/javascript-dev-guide/javascript/requirejs.html

Also, for more in-depth usage examples: refer to https://requirejs.org/docs/api.html#config-paths for paths and https://requirejs.org/docs/api.html#config-map for map

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.