モジュールを定義するために使用して、でJQuery
構築された Web アプリに含めようとしています。maven
RequireJS
Javascript
ここでは、 を使用する方法を説明しているRequireJS
ドキュメントに従いました。私はさらにビルドを持っています。JQuery
RequireJS
maven
これが私がしたことです:
私のmain.jsは、私のdata-mainによって呼び出されRequireJS
ますHTML
define(function() {
// Configuration of RequireJS
requirejs.config({
// No module can start with require. This can potentially allow easier definition of some elements
enforceDefine : true,
map : {
'*': {
'jquery': 'libs/jquery',
},
// To make jquery work with requireJS: see http://requirejs.org/docs/jquery.html
// 'jquery' wants the real jQuery module
// though. If this line was not here, there would
// be an unresolvable cyclic dependency.
'libs/jquery': { 'jquery': 'jquery' },
},
// The base URL is just the top-level directory where the files are stored
baseUrl : './',
// Kick-start the application by loading these files
deps : [ 'MyMainPanel' ],
});
});
/libs/jquery.js にある「カスタム」JQuery (RequireJS ドキュメントのように) を定義しました。
define(['jquery'], function (jq) {
return jq.noConflict( true );
});
そして私の中でmaven
pom.xml
:
...
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>${jquery.version}</version>
</dependency>
...
jquery を使用してモジュールをインスタンス化すると、次のエラーが発生します。
GET http://localhost:8080/jquery.js 404 (Not Found)
require.js:166 Uncaught Error: Script error for: jquery
http://requirejs.org/docs/errors.html#scripterror
JQuery を使用したモジュールは次のとおりです。
define(['ractive',
'jquery',
function(Ractive,
$,
){
var Panel = Ractive.extend({
el:"mainPanel",
oninit: function(){
$.ajax({url: "/myURL"}).done(function(types){
// Work
})
}
})
return Panel
})