我正在尝试使用 requirejs 捆绑我的 javascript 并在其之上构建。已经为 UI 操作和库使用开发了一些现有的 js 文件。
这些 js 文件需要在 jquery 包含之后立即包含,它还为网站中的社交媒体小部件执行操作。任何人,我写了下面的代码来尝试捆绑它们以在加载站点时执行,由于某种原因,我可以看到它们在 firebug 网络中加载。但是里面的代码失败了,因为它执行了不止一次..
以下是我的配置和要求声明,任何人都可以就为什么会发生这种行为提出建议?
'use strict';
require.config({
paths: {
jquery: '../vendors/jquery/jquery-1.10.2.min',
underscore: '../vendors/underscore/underscore-min-1.5.1',
backbone_query: '../vendors/backbone-query-parameters/backbone.queryparams',
backbone: '../vendors/backbone/backbone-min-1.0.0',
theme: '../vendors/theme/v1.9/scripts/'
},
shim: {
'jquery': {
exports: '$'
},
'underscore': {
exports: '_'
},
'backbone': {
deps: ['underscore', 'jquery'],
exports: 'Backbone'
},
'theme/base': {
deps: ['jquery']
},
'theme/message': {
deps: ['jquery', 'theme/base']
},
'theme/input_counter': {
deps: ['jquery', 'theme/base', 'theme/message']
},
'theme/placeholder': {
deps: ['jquery', 'theme/base', 'theme/message', 'theme/input_counter']
},
'theme/scrollbar': {
deps: ['jquery', 'theme/base', 'theme/message', 'theme/input_counter', 'theme/placeholder']
},
'theme/fields': {
deps: ['jquery', 'theme/base', 'theme/message', 'theme/input_counter', 'theme/placeholder', 'theme/scrollbar']
},
'theme/validate': {
deps: ['jquery', 'theme/base', 'theme/message', 'theme/input_counter', 'theme/placeholder', 'theme/scrollbar', 'theme/fields']
},
'theme/main': {
deps: ['jquery', 'theme/base', 'theme/message', 'theme/input_counter', 'theme/placeholder', 'theme/scrollbar', 'theme/fields', 'theme/validate']
}
}
});
require(['jquery', 'theme/base', 'theme/message', 'theme/input_counter',
'theme/placeholder', 'theme/scrollbar', 'theme/fields', 'theme/validate', 'theme/main']);