Does anyone have a working example of a (simple) ember-app project built using Ember-CLI that uses LoDash? (e.g.: I want to use lodash, _.someLodashFunc, in my Routes and Controllers).
I haven't seen any thread / article on the web that gives clear, step-by-step explanation on how to do that.
If possible with lodash v3.0.0 (and I'm using the latest ember-cli, v0.1.9).
Thanks, Raka
I found out how, you need to generate a custom build of lodash (the "lodash modern"). Use lodash-cli: https://lodash.com/custom-builds
On the command console type: lodash modern ..., and you'll get a javascript file generated: lodash.custom.js
Put that file under "vendor" dir of your ember-cli project.
Modify the Brocfile, add this:
app.import('vendor/lodash.custom.js', {
'lodash': [
'default'
]
});
And that's it.... you don't have to do "import _ from 'lodash'" in any of your js files. In fact, don't do that (you'll get an error). The _ var is readily available.
For example, I have a Route object like this:
import Ember from 'ember';
export default Ember.Route.extend({
model: function() {
console.log('hohoho: ' + _.chunk(['a', 'b', 'c', 'd'], 2));
return Ember.Object.create({name: 'Raka'});
}
});
And I could see hohoho:,b,c,d got printed in javascript console when I visited that route.
You don't really need that lodash-cli.
I've tried this way (I guess more proper):
That's it. _ is automatically available in your Routers / Controllers.
I did the same with d3:
And variable named 'd3' is automatically available.
Added related link:
You can use something ready: https://github.com/levanto-financial/ember-lodash or do it manually.
I don't have any example but it should be as easy as modifying these 3 files:
Just add the line
"lodash": "4.16.4",
to your dependencies
and run bower install
in your command line.
Alternatively, you can install it via bower
:
$ bower install lodash --save
In order to be included to sources by Broccoli:
app.import('bower_components/lodash/lodash.js');
add this somewhere after var app = new EmberApp();
Add the line:
"_": true,
somewhere in the predef
section (if you don't want to see the warnings like _ is undefined
).
I haven't tested that but I hope it helps :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With