プロジェクト内でこの構成を使用します。
startup.js
require.config({
paths: {
/* other paths are omitted */
'bootstrap': '../libs/bootstrap'
},
shim: {
'bootstrap/bootstrap-slider': { deps: ['jquery'], exports: '$.fn.slider' },
'bootstrap/bootstrap-affix': { deps: ['jquery'], exports: '$.fn.affix' },
'bootstrap/bootstrap-alert': { deps: ['jquery'], exports: '$.fn.alert' },
'bootstrap/bootstrap-button': { deps: ['jquery'], exports: '$.fn.button' },
'bootstrap/bootstrap-carousel': { deps: ['jquery'], exports: '$.fn.carousel' },
'bootstrap/bootstrap-collapse': { deps: ['jquery'], exports: '$.fn.collapse' },
'bootstrap/bootstrap-dropdown': { deps: ['jquery'], exports: '$.fn.dropdown' },
'bootstrap/bootstrap-modal': { deps: ['jquery'], exports: '$.fn.modal' },
'bootstrap/bootstrap-popover': { deps: ['jquery'], exports: '$.fn.popover' },
'bootstrap/bootstrap-scrollspy': { deps: ['jquery'], exports: '$.fn.scrollspy' },
'bootstrap/bootstrap-tab': { deps: ['jquery'], exports: '$.fn.tab' },
'bootstrap/bootstrap-tooltip': { deps: ['jquery'], exports: '$.fn.tooltip' },
'bootstrap/bootstrap-transition': { deps: ['jquery'], exports: '$.support.transition' },
'bootstrap/bootstrap-typeahead': { deps: ['jquery'], exports: '$.fn.typeahead' },
}
});
require(['domReady', 'app'], function(domReady, app) {
domReady(function() {
app.init();
});
});
次に、私のコードでこれを使用します:
define(['jquery', 'underscore', 'backbone', 'text!templates/photos-list.html'], function($, _, Backbone, html) {
var PhotosListView = Backbone.View.extend({
viewImageFullscreen: function(e) {
e.preventDefault();
require(['bootstrap/bootstrap-modal', 'text!templates/photo-modal.html'], function(modal, htmlModal) {
var modalTemplate = _.template(htmlModal, options);
$('body').append(modalTemplate);
// setup
$(selector + '_modal').modal({
backdrop: true,
keyboard: true,
show: false
}).css({
'width': function() { return ($(document).width() * 0.55) + 'px'; },
'margin-left': function() { return -($(this).width() * 0.5); }
});
// trigger `modal`
$(selector + '_modal').modal('show');
}); // require() call
// ...