@Tyson Phalp önerisine dayanarak, this SO question anlamına gelir.
Sorunuza uyarladım ve RequireJS 2.1.2 ve SHIM configuration'u kullanarak test ettim.
Sonra
require.config({
/* The shim config allows us to configure dependencies for
scripts that do not call define() to register a module */
shim: {
underscoreBase: {
exports: '_'
},
underscore: {
deps: ['underscoreBase'],
exports: '_'
}
},
paths: {
underscoreBase: '../lib/underscore-min',
underscore: '../lib/underscoreTplSettings',
}
});
require(['app'],function(app){
app.start();
});
bunu sevdiği templateSettings ile underscoreTplSettings.js
dosyası oluşturmak gerekir:
define(['underscoreBase'], function(_) {
_.templateSettings = {
evaluate: /\{\{(.+?)\}\}/g,
interpolate: /\{\{=(.+?)\}\}/g,
escape: /\{\{-(.+?)\}\}/g
};
return _;
});
Yani modül
underscore
içerecektir
Bu
main.js
dosyası bu requireJS yapılandırma nerede, olduğu altyazı kütüphanesi ve şablon ayarlarınız. Başvurunuz modülleri itibaren
sadece bu şekilde,
underscore
modülü gerektirir:
define(['underscore','otherModule1', 'otherModule2'],
function(_, module1, module2,) {
//Your code in here
}
);
ben sadece şüphe aynı sembol _
iki kez ihraç olmam, bile zor bu iş emin değilim bu iyi bir uygulama olarak kabul edilirse.
=========================
ALTERNATİF ÇÖZÜM: Bu aynı zamanda iyi çalışıyor ve bunu biraz sanırım Yukarıdaki çözüm olarak ekstra bir modül oluşturmayı ve gerektirmeyi önleyerek daha temiz. Bir başlatma işlevini kullanarak Shim yapılandırmasında 'dışa aktarma' değiştirdim. Daha fazla bilgi için Shim config reference'a bakın.
//shim config in main.js file
shim: {
underscore: {
exports: '_',
init: function() {
this._.templateSettings = {
evaluate:/\{\{(.+?)\}\}/g,
interpolate:/\{\{=(.+?)\}\}/g,
escape:/\{\{-(.+?)\}\}/g
};
return _; //this is what will be actually exported!
}
}
}
[Bu SO soru] (http://stackoverflow.com./questions/8842223/share-sources-across-different-amd-modules) bu duruma uygun bir çözüm olan bir cevabı vardır. –