Reputation: 81
I am trying to integrate a third-party library developed with Require.JS into a new Ember.JS application. I have looked at addons like ember-cli-amd and ember-auto-import but I cannot figure out how to make them work for a library loaded like so
<script data-main="jslib/app/LibConfig" type="text/javascript" src="jslib/modules/require.js"></script>
Upvotes: 1
Views: 337
Reputation: 12806
Welcome to Stack Overflow!
So you can't directly use require.js in Ember, but the Ember loader builds in a version of require.js for you. You just need to ensure that the library(ies) that you want to use are in named AMD or UMD format, and you can import them using app.import from your ember-cli-build file like this:
// ember-cli-build.js
'use strict';
const EmberApp = require('ember-cli/lib/broccoli/ember-app');
module.exports = function(defaults) {
let app = new EmberApp(defaults, {
// Add options here
});
// Use `app.import` to add additional libraries to the generated
// output files.
//
// If you need to use different assets in different
// environments, specify an object as the first parameter. That
// object's keys should be the environment name and the values
// should be the asset to use in that environment.
//
// If the library that you are including contains AMD or ES6
// modules that you would like to import into your application
// please specify an object with the list of modules as keys
// along with the exports of each module as its value.
app.import('vendor/my-awesome-named-amd-library.js');
return app.toTree();
};
For more information, see: https://ember-cli.com/user-guide/#standard-named-amd-asset
Alternatively, see if a version of the library you want to use is in npm, and ember-auto-import
can figure out the format and do the work for you.
Upvotes: 4