将require.js与第三方javascript库一起使用

lar*_*ryq 3 requirejs

我刚开始使用require.js并认为它很棒.但是,我想尽可能多地使用它,而不是<script>在我的HTML文件中处理标签.

为此,是否可以使用没有任何define模块的第三方库?这可能会让我意识到很多但是有办法打电话......

require(["3rd_party"], function(3rd) {
Run Code Online (Sandbox Code Playgroud)

});

... 3rd_party.js位于js文件夹中的脚本在哪里需要知道查看?我知道需要有映射库,require-jquery但不确定是否可以使用开箱即用的旧实用程序库,而不是用它构建的.

kry*_*ger 11

RequireJS2.1.0添加了shimconfig元素,允许使用非AMD第三方库,如AMD模块.在你的情况下,它将是这样的:

shim: {
    '3rd_party': {
        exports: '{the-global-name}' // what variable does the library
                                     // export to the global scope?
    }
}
Run Code Online (Sandbox Code Playgroud)

这种机制使得像"require-jquery"这样的自定义构建库包装器已经过时了.

RequireJS文档中的更多详细信息