Search code examples
ember.jsember-cli

How to use md5.js within a compontent?


I just started working with Ember-CLI 0.0.36 and I'm stuck with the Gravatar example code from the Ember.js homepage.

I did

> bower install --save JavaScript-MD5
> ember generate component gravatar-image

Brocfile.js

[...]
app.import('vendor/JavaScript-MD5/js/md5.js');
[...]

app/components/gravatar-image.js

import Ember from 'ember';

export default Ember.Component.extend({
  size: 200,
  email: '',

  gravatarUrl: function() {
    var email = this.get('email'),
        size = this.get('size');

    return 'http://www.gravatar.com/avatar/' + md5(email) + '?s=' + size;
  }.property('email', 'size')
});

After starting ember server I'll get the following error message:

xyz/components/gravatar-image.js: line 11, col 48, 'md5' is not defined.
1 error

How can I tell the component to use JavaScript-MD5?


Solution

  • JavaScript-MD5 does't export any AMD-Modules, if I see it right. But it defines window.md5. So your app.import will include it in vendor.js and you can call window.md5 in the component.