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?
Asked
Active
Viewed 5,971 times
11
-
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 – StateLess Mar 19 '15 at 07:26
-
11. Include lodash.js instead of underscore.js, 2. Done – ivarni Mar 19 '15 at 12:02
-
1replace underscore with lodash and fix possible errors) just wondering what are you going to reach by this replace? – Evgeniy Mar 19 '15 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. – ivarni Mar 19 '15 at 15:31
-
1As I remember, in our project we've just replaced an import of underscore with lodash and that's all. @Evgeniy, see: http://stackoverflow.com/a/13898916/1203773 – Eugene Naydenov Mar 19 '15 at 15:57
-
@EugeneNaydenov thanks for the SO link you provided! super helpful – wmock Mar 19 '15 at 18:38
3 Answers
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"
}
}

Michael
- 337
- 1
- 3
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

Guilherme Rodrigues
- 2,818
- 1
- 17
- 22
-
2There is documentation on doing a custom build and setting the moduleId to underscore https://lodash.com/custom-builds – Justin Hamade Nov 28 '15 at 01:08
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).

Matthew Optional Meehan
- 735
- 4
- 11
- 28

fstanis
- 5,234
- 1
- 23
- 42