The solution you already mentioned is an option (I think itβs better). I know about an alternative way, but I donβt necessarily think it is better, because it is more deceptive. You can reassign what "lodash" and "underscore" mean for different packages.
requirejs.config({ paths: { 'underscore': 'path-to-my-underscore-file', 'lodash': 'path-to-my-lodash-file' }, map: { 'some/lodash_compatible_module': { 'underscore': 'lodash' }, 'some/lodash_compatible_folder': { 'underscore': 'lodash' }, 'some/oldmodule_or_folder': { 'underscore': 'underscore' } } });
If you want to create a facade, you can also do something like this:
requirejs.config({ paths: { utils: 'lodash', 'underscore': 'path-to-my-underscore-file', 'lodash': 'path-to-my-lodash-file' }, map: { 'some/lodash_compatible_module': { 'utils': 'lodash' }, 'some/lodash_compatible_folder': { 'utils': 'lodash' }, 'some/oldmodule_or_folder': { 'utils': 'underscore' } } });
Although there are some negatives with this approach. There are some cool things. Namely, the ability to reassign dependencies of third parties can be considered a package (if this is a problem).
More details on how the map works: http://requirejs.org/docs/api.html#config-map
Parris
source share