Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I Update Meteor Underscore package?

Tags:

meteor

Meteor uses a very dated 1.5.2 version of Underscore. Two years old this Sept and missing a lot of great stuff that is in the current 1.8.2 library.

Can the package be updated?

like image 965
Pablo Avatar asked Mar 08 '15 17:03

Pablo


2 Answers

You can update the version used in your app, though not the version used by Meteor itself. See this GitHub issue.

The easiest solution is to just replace Underscore with Lodash, which has even more features than the latest Underscore. Per this thread, it’s this easy:

meteor add alethes:lodash

And in your startup code:

// Use lodash instead of underscore
_ = lodash;

If you prefer the latest Underscore instead of Lodash, it looks like at the moment you’ll need to download the file from underscorejs.org and save it into either your lib or client/compatibility folder. It should execute after Meteor’s libraries themselves load, and hijack the _ variable. You can also initialize it with _.noConflict(), in which case you can let _ stay with Meteor’s version and you can assign the new Underscore to something else, e.g. underscore = _.noConflict();.

I should probably mention that either of these solutions will leave you with both libraries (Meteor’s old version of Underscore, and the new library you’re using instead) downloading to the client. Until Meteor itself upgrades (see GitHub issue above), that is unavoidable.

like image 193
Geoffrey Booth Avatar answered Oct 27 '22 18:10

Geoffrey Booth


My solution using lodash with Meteor ES2015:

meteor npm i lodash --save

and import lodash /imports/startup/client/index.js:

import lodash from 'lodash'; window._ = lodash;

Regards, Nicholls

like image 44
jdnichollsc Avatar answered Oct 27 '22 19:10

jdnichollsc