David Ferris David Ferris - 2 months ago 23
Javascript Question

How to use javascript library? (Ember JS)

Simple question here, but I can't seem to figure out how to use a dependency I've installed in my ember JS app. I installed the twitter fetcher library via bower.

enter image description here

I have a twitter-container component, and inside of my component.js:

import Ember from 'ember';
export default Ember.Component.extend({
loadPlugin: function() {
var config1 = {
"id": 'XXXXXXXXXXXXXXX',
"domId": 'example1',
"maxTweets": 1,
"enableLinks": true
};
twitterFetcher.fetch(config1);
}.on('init')
});


I get a 'twitterFetcher is not defined' error (obviously), but am not sure how to import it. Should I include a line like this?

import twitterFetcher from 'bower_components/twitter-fetcher'

Answer

In ember-cli-build.js, you need to include the below line to bundle it in ember app,

app.import('bower_components/twitter-fetcher/js/twitterFetcher_min.js')