load__amd.js 885 B

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