Dynamically require modules
ember install ember-require-module
If it is a bug please open an issue on GitHub.
import requireModule from 'ember-require-module';
const moment = requireModule('moment');
// requireModule will return undefined if moment is not found
assert('MomentJS is required!', moment);
// Dynamically require modules when needed
function runTask(taskName, ...params) {
let task = requireModule(`my-addon/tasks/${taskName}`);
assert(`The task ${taskName} does not exist.`, task);
return task.run(...params);
}
// import a named export from a module
const THING = requireModule('path-to-module', 'THING');