load__amd.js 900 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. 'use strict';
  6. // We import the 'require' module, so Require.JS gives us a localized version of require().
  7. // Otherwise we would use the global one which resolves paths relatively to the base dir.
  8. import require from 'require';
  9. /**
  10. * Loads a module.
  11. *
  12. * load( 'ckeditor5/editor.js' )
  13. * .then( ( EditorModule ) => {
  14. * const Editor = EditorModule.default;
  15. * } );
  16. *
  17. * @param {String} modulePath Path to the module, relative to `ckeditor.js`'s parent directory (the root).
  18. * @returns {Promise}
  19. */
  20. export default function load( modulePath ) {
  21. modulePath = '../' + modulePath;
  22. return new Promise( ( resolve, reject ) => {
  23. require(
  24. [ modulePath ],
  25. ( module ) => {
  26. resolve( module );
  27. },
  28. ( err ) => {
  29. reject( err );
  30. }
  31. );
  32. } );
  33. }