ember-require-module
v0.4.0
Published
Easily require a module which will silently fail if it is not found.
Downloads
55,486
Readme
ember-require-module
Dynamically require modules
Installation
ember install ember-require-module
Looking for help?
If it is a bug please open an issue on GitHub.
Usage
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');
Compatibility
See the Changelog
- Ember.js v3.24 or above
- Ember CLI v3.24 or above
- Node.js v12 or above
Contributing
See the Contributing guide for details.
License
This project is licensed under the MIT License.