Etienne Noël
Etienne Noël

Reputation: 6166

How to import non amd library ember-cli

I am using Ember-CLI and now I faced the problem of importing AmplifyJS in my project. I downloaded Amplify using Bower however the library is not in an ES6 format. Therefore, when I try to use it in my project, I simply can't import it.

Basically I would want to do:

import Amplify from amplify;

//use amplify here

Brocfile.js

app.import('bower_components/amplify/lib/amplify.js');

Since a lot of libraries are no in the ES6 format yet, my question is: "Is there a way to easily import or use ES5 librairies in ES6".

If not, what is the recommended way of doing that in Ember?

Upvotes: 1

Views: 545

Answers (2)

kushdilip
kushdilip

Reputation: 7906

If you look at line 15 of the code https://github.com/mikehostetler/amplify/blob/master/lib/amplify.js#L15, library is attaching itself to global which is passed in here https://github.com/mikehostetler/amplify/blob/master/lib/amplify.js#L124

So basically you can directly use the global version of library anywhere like amplify.subscribe(...)

Upvotes: 0

HeroicEric
HeroicEric

Reputation: 876

You can't import Amplify from amplify; because it's not a module.

You've almost got it but just don't try to import the library. You need to reference it as a global the way that you would outside of an ember-cli app.

From the docs:

Provide the asset path as the first and only argument:

app.import('bower_components/moment/moment.js');

From here you would use the package as specified by it’s documentation, usually a global variable. In this case it would be:

import Ember from 'ember';
/* global moment */
// No import for moment, it's a global called `moment`

// ...
var day = moment('Dec 25, 1995');

Note: Don’t forget to make JSHint happy by adding a /* global MY_GLOBAL */ to your module, or by defining it within the predefs section of your .jshintrc file.

-- http://www.ember-cli.com/#standard-non-amd-asset

Upvotes: 1

Related Questions