希望这是一个相当简单的答案。我正在尝试将Twitter引导插件的AMD版本加载到我的require模块中,该模块使用的是没有冲突的jquery版本(我需要无冲突版本,因为我在一些遗留代码中有另一个jquery对象)。
但是,我无法让AMD插件将方法添加到我正在定义的需求模块中的无冲突jquery对象中。有人知道我做错了什么吗?看起来应该是显而易见的。
AMD引导模块来自于这里:https://github.com/clexit/bootstrap-amd
这是我的密码。
require.config({
map: {
'*': { 'jquery': 'jquery-private' },
'jquery-private': { 'jquery': 'jquery' }
},
paths : {
jquery : '../bower_components/jquery/jquery',
underscore : '../bower_components/underscore/underscore',
backbone : '../bower_components/backbone-amd/backbone',
marionette : '../bower_components/marionette/lib/core/amd/backbone.marionette',
'backbone.wreqr' : '../bower_components/backbone.wreqr/lib/amd/backbone.wreqr',
'backbone.babysitter' : '../bower_components/backbone.babysitter/lib/amd/backbone.babysitter',
'localstorage' : '../bower_components/backbone.localStorage/backbone.localStorage',
handlebars : '../bower_components/handlebars/handlebars',
text: '../bower_components/requirejs-text/text',
hb: '../bower_components/requirejs-handlebars/hb',
bootstrap: '../bower_components/bootstrap/amd'
},
shim : {
underscore : {
exports : '_'
},
handlebars: {
exports: 'Handlebars'
}
}
});
require(['jquery', 'bootstrap'],function($){
console.log($);
$('#MainRegion').modal();
});
发布于 2014-01-25 19:59:05
我有一个关于github的存储库,即演示如何做到这一点。
在这个演示中,我加载了jQuery 1.8.3,如下所示:
<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
然后是RequireJS load jQuery 1.10.2:
require.config({
baseUrl: "./js",
paths: {
jquery: 'jquery-1.10.2'
},
packages: [
{ name: "bootstrap", location: "../bootstrap/amd" }
],
map: {
'*': { 'jquery': 'jquery-private' },
'jquery-private': { 'jquery': 'jquery' }
},
});
我注意到在您的配置中,您没有使用packages
选项,这会导致RequireJS加载引导失败。map
的繁文缛节是您在另一个问题中所解释的,并记录了这里。
然后我可以用下面的代码来测试它:
console.log("Non-AMD version of jQuery", $.fn.jquery, $.fn.modal);
require(["jquery", "bootstrap"], function ($) {
console.log("AMD version of jQuery", $.fn.jquery, $.fn.modal);
$(".modal").modal();
});
演示中的index.html
文件包含模式显示所必需的脚手架。该模型确实显示出来,证明Bootstrap安装在由RequireJS加载的RequireJS版本上。
https://stackoverflow.com/questions/21354773
复制相似问题