Is there a way to have RequireJS modules depend on code loaded with <script>?

荒凉一梦 提交于 2019-11-29 16:22:56

The way to do it is like this:

define('jquery', [], function () {
    return jQuery;
});

This just takes the jQuery normally loaded through script and makes it available as a RequireJS module

The same principle also works with any other library loaded before RequireJS and which exports itself as a symbol in the global space: just create a fake module for it that merely returns the symbol the library exports in the global space.

You could put that code in a separate file called jquery.js and have the define be define([], function () { (without the module name) but I don't see much benefit to doing that. I prefer to call define with the module name as in my first snippet above and put the definition just before my call to require.config.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!