springrolls springrolls - 1 year ago 176
Javascript Question

RequireJS optimizer - Oracle MapViewer has more than one anonymous define

I use RequireJS 2.2.0 for my project with the following configuration:

require.config({
baseUrl: "Scripts/js/kendo",
paths: {
"kendo.datepicker.min": "kendo.datepicker.min",
"jquery-ui": "../../lib/jquery-ui.min",
"modules": "../../modules",
"colorpicker": "../../lib/colorpicker",
"eye": "../../lib/eye",
"layout": "../../lib/layout",
"utils": "../../lib/utils",
"oraclemaps": "../../lib/oraclemapsv2"
},
shim: {
"kendo.datepicker.min": ["oraclemaps"],
"jquery-ui": ["oraclemaps"],
"colorpicker": ["jquery-ui"],
"eye": ["colorpicker"],
"layout": ["eye"],
"utils": ["layout"]
}
});


oraclemaps
is a third party library which includes jQuery. I use their version, so I defined Kendo and jQuery-UI dependencies in shim. oraclemaps has a component which requires
jquery-ui, colorpicker, eye, layout, and utils
in the mentioned order. This I have defined in shim as well. The application runs well.

The problem is now with the optimizer. Using the configuration, I got an error
oraclemapsv2.js has more than one anonymous define
. I googled it and I found that this is an issue of jQuery Hammer (which is included in oraclemaps). Running the app leads to
mismatched anonymous define() module
.

I tried putting oraclemaps in
exclude/excludeShallow
and loading it in HTML, but I got
Script error for "jquery", needed by: jquery-ui, kendo.core.min
.

Here is my optimizer configuration:

({
baseUrl: "../js/kendo",
paths: {
"kendo.datepicker.min": "kendo.datepicker.min",
"jquery-ui": "../../lib/jquery-ui.min",
"modules": "../../modules",
"colorpicker": "../../lib/colorpicker",
"eye": "../../lib/eye",
"layout": "../../lib/layout",
"utils": "../../lib/utils",
"oraclemaps": "../../lib/oraclemapsv2"
},
shim: {
"kendo.datepicker.min": ["oraclemaps"],
"jquery-ui": ["oraclemaps"],
"colorpicker": ["jquery-ui"],
"eye": ["colorpicker"],
"layout": ["eye"],
"utils": ["layout"]
},
include: ["../../lib/require.min"],
exclude: ["oraclemaps"],
name: "../../app",
out: "../build/app-built.js"
})


What should I do? Any ideas?

Answer Source

There's nothing the r.js optimizer can do to understand files that contain multiple anonymous define calls.

You have to find a build of oraclemaps that does not include multiple anonymous define calls. (Which means you have to get jQuery and of the Kendo datepicker else where than oraclemaps.) If such a build is not available, you could process oraclemaps to rip out the extra modules. Or you could process it so to add names to the define calls.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download