RequireJS 2.0.1 ile biraz deneme yapıyorum. Amacım jQuery, Underscore ve Backbone'ı doğru şekilde yüklemektir. Orijinal RequireJS doc'dan, yazar J. Burke'ün (bu yeni sürümde) bir new config option called shim eklediğini keşfettim.RequireJS 2.0.1 ve shim kullanarak jQuery, Underscore ve Omurga yükleme
Sonra aşağı Bunları buraya yazdım:
index.html
<!DOCTYPE html>
<html>
<head>
<title>Testing time</title>
<script data-main="scripts/main" src="scripts/require.js"></script>
</head>
<body>
<h1>Testing time</h1>
</body>
</html>
scripts/main.js
requirejs.config({
shim: {
'libs/jquery': {
exports: '$'
},
'libs/underscore': {
exports: '_'
},
'libs/backbone': {
deps: ['libs/underscore', 'libs/jquery'],
exports: 'Backbone'
}
}
});
define(
['libs/jquery', 'libs/underscore', 'libs/backbone'],
function (jQueryLocal, underscoreLocal, backboneLocal) {
console.log('local', jQueryLocal);
console.log('local', underscoreLocal);
console.log('local', backboneLocal);
console.log('global', $);
console.log('global', _);
console.log('global', Backbone);
}
);
Her şey oldukça iyi çalışıyor görünüyor, ama ben bir şey eksik duygu var , JQuery ve Underscore'un AMDed sürümünün olduğunu biliyorum, ancak se tup o kadar basit ki neden onları kullanmalıyım anlamıyorum.
Bu kurulum doğru mu yoksa bir şey mi eksik?
'json2' nasıl? Buna da ihtiyacımız var mı? – Henry