Package Exports
- ember-require-module
- ember-require-module/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ember-require-module) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
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.