質問

AMDのrequirejsを使用するプロジェクトでjQuery Mobileを含めようとしていますが、jQuery MobileをAMDモジュールとしてロードしたくない。この背後にある考え方は、アプリケーション固有のロジックのためにAMDを使用することになりますが、スクリプトタグを手動で定義するだけで、jQueryなどの外部ライブラリ依存関係がグローバルスコープにされます。

jQuery Mobileのスクリプトタグを定義している問題jsスクリプトタグは、require Moduleが匿名モジュールを定義し、わかりません競合を発生させるようです。 jQueryモバイルコードとjQueryモバイルコードの両方を見て、それが存在する場合は、define()メソッドを条件付きで呼び出すように設定されています。 Requirejsロードの前にそれらのタグを含めているので、それらはdefine()を呼び出すべきではありません。私はこれをブレークポイントで2倍にし、彼らは実際にはそうではありません。

jQuery Mobileを含めると、次のエラーが発生します。

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

jQuery Mobileがdefine()を呼び出していない場合、これがどのように起こっているかわかりません。私はここで何をしていますか?これはjQuery Mobileの新しい条件付きAMDサポートをサポートしているものですか?

役に立ちましたか?

解決

To confirm, you should be using the built version of jQuery mobile, and you should include it before the require.js tag like so -- notice 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 that to work. The error you see may be generated if you have the scripts like this:

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

I consider this more of a problem with RequireJS, not jQuery mobile, something I want to fix for RequireJS 1.1. But the first set of script tags should work.

If that does not, it would be interesting to know more how your app's JS module uses jQuery and jQuery mobile.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top