0.4.0 • Published 2 years ago

ember-require-module v0.4.0

Weekly downloads
53,735
License
MIT
Repository
github
Last release
2 years ago

ember-require-module

Build Status Ember Observer Score npm version

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.