11

I'm writing a Backbone application and as I'm reading the documentation online, what I understand is that Backbone's only hard dependency is Underscore. However, I'd like to use Lodash instead of Underscore. Can someone provide steps as to how I can do this?

6
  • backbone depends a lot on underscore to get it job done. you might need to write complete library again in case you dont want to use underscore Commented Mar 19, 2015 at 7:26
  • 1
    1. Include lodash.js instead of underscore.js, 2. Done Commented Mar 19, 2015 at 12:02
  • 1
    replace underscore with lodash and fix possible errors) just wondering what are you going to reach by this replace? Commented Mar 19, 2015 at 12:29
  • 3
    @Evgeniy lodash has some features that underscore lack, if OP wants to use those features it makes more sense to replace underscore than to add both. Commented Mar 19, 2015 at 15:31
  • 1
    As I remember, in our project we've just replaced an import of underscore with lodash and that's all. @Evgeniy, see: stackoverflow.com/a/13898916/1203773 Commented Mar 19, 2015 at 15:57

3 Answers 3

9

If you are using Browserify, check out Browserify Swap or Aliasify

Personally I use Browserify Swap. Example package.json usage:

  "browserify": {
    "transform": [
      "browserify-swap"
    ]
  },
  "browserify-swap": {
    "@packages": [
      "underscore"
    ],
    "all": {
      "underscore.js$": "lodash"
    }
  }
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for sharing this - will definitely try this!
3

Up to version 2.4.1, lodash published a "Underscore compatible" version.

https://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.underscore.js

You can use that as a drop-in replacement.

As of 3.0, they removed this build.

Removed the underscore build

https://github.com/lodash/lodash/wiki/Changelog

1 Comment

There is documentation on doing a custom build and setting the moduleId to underscore lodash.com/custom-builds
2

You could also check out Exoskeleton - it's a drop-in replacement for Backbone that doesn't have Underscore as a requirement so you can simply remove it (and use lodash instead of it).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.