Require.js Shim for loading JQuery UI and other JQuery Packages

落爺英雄遲暮 提交于 2019-12-07 03:06:17

问题


I am trying to load JQuery-Ui with a shim, but JQueryUi keeps timing out when I try to load it even when I know the path is correct.

require.config({
paths: {
    jQuery: 'libs/jquery-wrapper',
    jQueryUi: 'libs/jquery-ui-min',
    jQuerySelectmenu: 'libs/jquery.ui.selectmenu',
    Underscore: 'libs/underscore-wrapper',
    Backbone: 'libs/backbone-wrapper',
},
shim: {'Backbone': {
          //These script dependencies should be loaded before loading
          //backbone.js
          deps: ['Underscore', 'jQuery'],
          //Once loaded, use the global 'Backbone' as the
          //module value.
          exports: 'Backbone'
      },
      'jQueryUi': {
          deps: ['jQuery'],
      },
      'jQuerySelectmenu': {
          deps: ['jQuery', 'jQueryUi']
      }
  }  
});

require([
    'jQuery',
    'Underscore',
    'Backbone',  
    'jQueryUi',
    'jQuerySelectmenu'  
], 
    function(App) {
        require(['order!src/app']
     ,     function (App) {
    App.initialize();
}); 
});

回答1:


I think what damee is offering stands for older version of requireJs. Just folllow this tutorial as I did: Load jQuery UI with requireJS




回答2:


Try to use this project https://github.com/jrburke/jqueryui-amd to translate your jqueryui to modularized version. Then you can simply use it:

define(['jquery', 'jqueryui/tabs'], function($){
    $('#tabs').tabs();    
});

With requirejs config:

requirejs.config({
paths: {
    'jqueryui': '/javascript-cdn/jqueryui/' //output form jqueryui-amd
}, 
shim: {
    'jquery': {
        deps: [], 
        init: function(){
            return $; 
        }
    },        
    'jqueryui': {
        deps: ['jquery'] 
    }
}
});

I hope this helps.



来源:https://stackoverflow.com/questions/11346270/require-js-shim-for-loading-jquery-ui-and-other-jquery-packages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!