运行Require.js Optmizer后,JQuery插件无法使用
这是我的 main.js。正如您所看到的,这是非常基本的。我只需要一个 jquery 插件。
//main.js
require.config({
paths: {
jquery: 'lib/jquery/jquery-1.7.1.min',
underscore: 'lib/underscore/underscore-min',
backbone: 'lib/backbone/backbone-optamd3-min',
text: 'lib/requirejs/text',
bootstrap_dropdown: 'lib/bootstrap/bootstrap-dropdown',
}
});
require([
'app',
'bootstrap_dropdown', //LOAD THE JQUERY PLUGIN!!
], function(App){
App.initialize();
});
这是我的 app.js
//app.js
define([
'jquery',
'underscore',
'backbone',
'router',
], function($, _ , Backbone, Router){
var initialize = function(){
$(function(){
$("#menu_topbar").dropdown();
});
Router.initialize();
}
return {
initialize: initialize
};
});
当我正常运行网站(没有优化)时,一切正常,并且可以使用下拉插件。但是当我优化时,它说它没有 no method dropdown();
由于某种原因,插件没有加载,这很奇怪。我查看了我的组合 js 文件,我在其中看到了该插件!
这是我的 build.js:
({
paths: {
jquery: 'lib/jquery/jquery-1.7.1.min',
underscore: 'lib/underscore/underscore-min',
backbone: 'lib/backbone/backbone-optamd3-min',
text: 'lib/requirejs/text',
bootstrap_dropdown: 'lib/bootstrap/bootstrap-dropdown',
},
baseUrl:'.',
appDir:'./',
dir: '../prod_js',
optimize: 'none',
optimizeAllPluginResources:false,
findNestedDependencies:true,
inlineText: true,
modules: [
{
name: 'main',
}
]
})
它不仅仅是这个插件。我可以选择任何其他插件,但它不起作用。
我还尝试了 require-jquery.js,我现在正在使用它。还是同样的问题。
当我将“alert('test')”放入 bootstrap-dropdown.js 中时,它会发出警报。
This is my main.js. As you can see, it's very basic. I just require a jquery plugin.
//main.js
require.config({
paths: {
jquery: 'lib/jquery/jquery-1.7.1.min',
underscore: 'lib/underscore/underscore-min',
backbone: 'lib/backbone/backbone-optamd3-min',
text: 'lib/requirejs/text',
bootstrap_dropdown: 'lib/bootstrap/bootstrap-dropdown',
}
});
require([
'app',
'bootstrap_dropdown', //LOAD THE JQUERY PLUGIN!!
], function(App){
App.initialize();
});
This is my app.js
//app.js
define([
'jquery',
'underscore',
'backbone',
'router',
], function($, _ , Backbone, Router){
var initialize = function(){
$(function(){
$("#menu_topbar").dropdown();
});
Router.initialize();
}
return {
initialize: initialize
};
});
When I run the site normally (without optimizing), everything works, and the dropdown plugin can be used. But when I optimize, it says that it has no method dropdown();
For some reason that plugin is not loaded, which is weird. I look in my combined js file, and I see the plugin in there!
This is my build.js:
({
paths: {
jquery: 'lib/jquery/jquery-1.7.1.min',
underscore: 'lib/underscore/underscore-min',
backbone: 'lib/backbone/backbone-optamd3-min',
text: 'lib/requirejs/text',
bootstrap_dropdown: 'lib/bootstrap/bootstrap-dropdown',
},
baseUrl:'.',
appDir:'./',
dir: '../prod_js',
optimize: 'none',
optimizeAllPluginResources:false,
findNestedDependencies:true,
inlineText: true,
modules: [
{
name: 'main',
}
]
})
It's not only this plugin. I can choose any other plugin and it won't work.
I also tried require-jquery.js, which I am now using. Still the same problem.
When I put "alert('test')" inside bootstrap-dropdown.js, it does alert.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决了。
在我的 app.build.js 模块中添加了“排除:['jquery']”。
Solved.
Added "exclude: ['jquery']" to my app.build.js's module.