RequireJS 和 shim 库与 AMD 不兼容硒

RequireJS and shim libraries not AMD compatible with selenium

您好,我最近将我的应用更改为 requireJS 结构,并将所有第 3 方库修改为 shim 配置。但是当我 运行 我在我的应用程序中进行集成测试时,我遇到了一些失败。

requirejs.config({
baseUrl: 'resources/js/lib/',
shim : {
    'bootstrap' : {deps: ['jquery']},
    'bootstrap-datepicker': { deps: ['jquery', 'bootstrap']},
    ...
},
paths: {
    'app': '../app',
    'jquery': 'jquery-1.11.1',
    'bootstrap' : 'bootstrap',
    'bootstrap-datepicker': 'bootstrap-datepicker',
    ...
}

});

但我失败了

$(...).collapse() its not a function.
$(...).datepicker() its not a function.

我发现问题在于与 AMD 不兼容的库,如 (bootstrap.js、bootstrap-datepicker.js、chosen.js、...)

有一些方法可以解决 requireJS 和非 AMD 库的这个问题吗?

谢谢

我找到了解决办法,希望能对遇到同样问题的大家有所帮助。

  1. 您需要正确使用 requirejs.config 并添加您的 shim 库的所有相关依赖项。无需使用导出功能。

  2. 重要请务必使用与 AMD 兼容的所有第 3 方库

  3. 如果您有一些与 AMD 不兼容的第三方库,您可以按照此页面 https://github.com/umdjs/umd 轻松转换为 AMD。最好的最佳选择是使用与 AMD 兼容的第三方库。