を使用してjQuery、Underscore、およびBackboneをロードしています。RequireJSで少し実験しています2.0.1私の目標は、正しくjQuery、Underscore、およびBackboneをロードすることです。元のRequireJS docから、私は、著者Burkeがこの新しいリリースにnew config option called shimを追加したことを発見しました。RequireJS 2.0.1とshim
は、その後、私はダウンし、ここでこのようなものを書いた:
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);
}
);
すべてが非常にうまく動作するようだが、私は何かが欠けてる気がします、私はあることを知っているのAMDed jQueryとアンダースコアのバージョンが、 tupはとてもシンプルなので、なぜ私はそれらを使うべきか理解できません。
この設定は正しいですか、何か不足していますか?
「json2」についてはどうですか?それも必要ですか? – Henry