jquery vector maps을 require.js를 모듈로 사용하려면 어떻게해야합니까?JQVMAP with requirejs
JVP는 호환됩니까? 누군가가 예제에 링크하거나 해결 방법을 제안 할 수 있다면 좋을 것입니다.
이전 require.js를 사용하고있어 업데이트 할 수 없어 shim 옵션을 사용할 수 없습니다.
jquery vector maps을 require.js를 모듈로 사용하려면 어떻게해야합니까?JQVMAP with requirejs
JVP는 호환됩니까? 누군가가 예제에 링크하거나 해결 방법을 제안 할 수 있다면 좋을 것입니다.
이전 require.js를 사용하고있어 업데이트 할 수 없어 shim 옵션을 사용할 수 없습니다.
define
으로 라이브러리를 포장하여 shim
옵션의 효과를 효과적으로 달성 할 수 있습니다. 빠른 테스트 설정 :
jqvmap-wrapped.js
// to simplify the example used jQuery named as "jquery.js"
define(['jquery'], function(jQuery){
// original jqvmap.js goes here
// (...)
// please note: not returning anything
});
index.html을
<html>
<head>
<script data-main="index" src="require.js"></script>
</head>
<body>
<div id="vmap" style="width: 600px; height: 400px;"></div>
</body>
</html>
하는 index.js
define(['jquery', 'jqvmap-wrapped'], function ($, _jqvmapEmpty) {
console.log('jQuery=', $);
console.log('jqvmap-wrapped=', _jqvmapEmpty);
console.log('jqvmap attached to jQuery? ', $.prototype.vectorMap);
$('#vmap').vectorMap({
// params
});
})
설명의 단어 : 플러그인이 jQuery에 자신을 추가하고 "독립형"버전이 없습니다. 래퍼 모듈은 아무 것도 반환하지 않으며 단지 jQuery
객체에 jqvmap
을 추가하는 부작용이 있습니다. 그렇기 때문에 _jqvmapEmpty
변수 자체는 undefined
입니다. 하지만 jQuery를 통해 사용할 수 있으므로 모듈화되지 않은 코드에서 사용하는 것과 같은 방식으로 사용할 수 있습니다.