This is how jQuery announces its AMD. This is just a bunch of if statements. If libraries do not have library.AMD === true , then there is no way to check it from the library itself.
if ( typeof module === "object" && module && typeof module.exports === "object" ) { module.exports = jQuery; } else { window.jQuery = window.$ = jQuery; if ( typeof define === "function" && define.amd ) { define( "jquery", [], function () { return jQuery; } ); } }
However, there is a way to check already loaded modules. This answer says that you can check require.s.contexts._.defined , which is an object containing a mapping of names and already loaded modules.
For example, if I loaded jQuery (which AMD has by default) on a page that also has RequireJS, the jquery property will exist in this object and contain the same jQuery object as the global one. Then you can compare. The following will return true :
require.s.contexts._.defined.jquery === jQuery require.s.contexts._.defined.jquery === $
However, this assumes that you know the name of the module and / or is global for comparison. This may not work in all cases. For example, the jQuery user interface is not just one big piece of code. This is a bunch of plugins hosted under jquery-ui.js . There is a possibility that either they can be called collectively, or a module for each widget. The jQuery user interface does not even have a global one.
Joseph
source share