Separation of jQuery Mobile (1.1.0) from AMD (RequireJS)

I am trying to include jQuery Mobile in a project that uses RequireJS for AMD, however I do not want to load jQuery Mobile as an AMD module. The idea is that we will use AMD for a specific application logic, but any external dependent libraries such as jQuery will be transferred to the global scope simply by defining script tags manually.

The problem I am facing is defining a script tag for jQuery mobile before the RequireJS script tag, which apparently causes the RequireJS requirement to define an anonymous module and create a conflict that I don't understand. I looked at the jQuery and jQuery Mobile code and they are set up to conditionally call the define() method if it exists. Since I include those tags before loading RequireJS, they should not call define() . I tested this twice with breakpoints, and they really don't.

When I turn on jQuery Mobile, I get the following error:

  Error: Mismatched anonymous define () module: [object Object] 

I do not understand how this happens if jQuery Mobile does not call define() . What am I doing wrong here? Is this something with jQuery Mobile support for AMD's new conditional support?

+4
source share
1 answer

To confirm that you must use the built-in version of jQuery mobile, and you must include it before the require.js tag like this, note that jquery is included as a script tag, since jQuery mobile depends on it:

 <script src="scripts/jquery.js"></script> <script src="scripts/jquery.mobile.js"></script> <script src="scripts/require.js" data-main="scripts/app"></script> 

I expect this to work. The error you see can be generated if you have such scripts:

 <script src="scripts/require.js" data-main="scripts/app"></script> <script src="scripts/jquery.js"></script> <script src="scripts/jquery.mobile.js"></script> 

I am considering this issue with RequireJS, not jQuery mobile, which I want to fix for RequireJS 1.1. But the first set of script tags should work.

If this is not the case, it would be interesting to know how your JS application module uses jQuery and jQuery mobile.

+4
source

Source: https://habr.com/ru/post/1399242/


All Articles