Search code examples
javascriptrequirejsunderscore.jsamdlodash

Using Lo-Dash and Underscore simulatenously in RequireJS environment


In a RequireJS environment, what's the best way to allow some AMD modules to use Lo-Dash while others simultaneously use Underscore?


Solution

  • I was able to solve the problem myself fairly simply. Specifically use the lodash path for modules that require Lo-Dash and underscore for modules that require "underscore":

    require.config({
      paths: {
        'underscore': 'path-to-my-underscore-file',
        'lodash': 'path-to-my-lodash-file'
      }
    });
    

    In this way, the two libraries can be used simultaneously without any interference.

    Contrary to popular belief and claims, Lo-Dash is not a perfect drop-in replacement for Underscore.