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?
-
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 underscoreStateLess– StateLess2015-03-19 07:26:06 +00:00Commented Mar 19, 2015 at 7:26
-
11. Include lodash.js instead of underscore.js, 2. Doneivarni– ivarni2015-03-19 12:02:08 +00:00Commented Mar 19, 2015 at 12:02
-
1replace underscore with lodash and fix possible errors) just wondering what are you going to reach by this replace?Evgeniy– Evgeniy2015-03-19 12:29:16 +00:00Commented 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.ivarni– ivarni2015-03-19 15:31:39 +00:00Commented Mar 19, 2015 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: stackoverflow.com/a/13898916/1203773Eugene Naydenov– Eugene Naydenov2015-03-19 15:57:47 +00:00Commented Mar 19, 2015 at 15:57
3 Answers
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"
}
}
1 Comment
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
1 Comment
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).