2

I'm not sure what causes this, but jquery-ui doesn't seem to work after optimization.

Without optimization, the project runs fine. $ contains $.ui. (Let's call this develop)

After optimization, functions depending on jquery-ui fail because $.ui does not exist.

I've been messing around with shims and requires for hours, but the result is always the same (or worse, $ not even working, although it still works in the non-optimized version.

What piece of logic am I missing?


requirejs.config({
    baseUrl     : 'js',
    waitSeconds : 10,
    urlArgs     : 'cache='+Date.now(),

    paths: {
        "conf"              : "remix/config",
        "jquery"            : "lib/jquery",
        "jqueryUi"          : "lib/jquery.ui",
        "domReady"          : "lib/domReady",
        "bootstrap"         : "lib/bootstrap",
        "jsviews"           : "lib/jsviews"
    },

    // I've had many configurations. 
    // Basically, develop almost always works, optimized never works.
    shim: {
        "jqueryUi"  : {
            deps        : ['jquery']
        },
        "jsviews"   : {
            deps        : ['jqueryUi']
        },
        "bootstrap" : {
            deps        : ['jsviews']
        }
    }

});

require(['domReady!', 'jsviews', 'jqueryUi', 'bootstrap'], function() {
    console.log($);
    // Develop: $.ui exists
    // Optimized: $ exists, $.ui does not. 
    // (And jsviews only in some modules.)
});
Redsandro
  • 11,060
  • 13
  • 76
  • 106

1 Answers1

-1

According to answer: https://stackoverflow.com/a/17536078/2463365 and refernced tutorial: Load jQuery UI with requireJS. I've just added exports: '$'

shim: {
    "jqueryUi"  : {
        exports     : '$',
        deps        : ['jquery']
    },

and it works.

Community
  • 1
  • 1
Kiryl
  • 180
  • 13
  • 1
    Merely adding the `exports` setting won't fix the problem described in the question. – Louis Dec 01 '14 at 12:59
  • I've returned to this issue in my case the issue was cused by second entry point that calls directly to not-optimized module. 1. I've load requirejs; 2. I've load config fo requirejs; 3. I've run script that reuire some utils module directly; 4. I've run script that require minified builded script and call main entry poin in scope of it. So I end up with 2 instances of jquery (first as dependency of 3, unminified; second from builded optimixed script from p.3). After I've refactore code and remove p.3 my problem is go avay. – Kiryl Dec 10 '14 at 07:50
  • @Kiryl I don't really understand. Can you update your answer? – Redsandro Jan 27 '15 at 20:14