Require js shim doesn't work for this code
I have the following code.
<script src="js/libs/require.js"></script>
<script>
requirejs.config({
baseUrl:'js/modules/',
paths:{
'bbn':'../libs/backbone',
'underscore':'../libs/underscore'
},
shim:{
'bbn':{
exports:'B',
deps:['underscore']
}
}
})
requirejs(['bbn'], function(B){
console.log(B)
});
</script>
The function parameter B
does not point to Backbone
. Instead, it is registered as undefined
.
I followed the following post and got to this point:
Loading Highcharts with shim using RequireJS and jQuery dependency support
I can see how files underscore
and Backbone
JavaScript are loaded in firebug.
source to share
Underlining is also not AMD compatible, so make sure you do too shim
:
requirejs.config({
baseUrl:'js/modules/',
paths:{
'bbn':'../libs/backbone',
'underscore':'../libs/underscore'
},
shim:{
'bbn':{
exports:'Backbone',
deps:['underscore']
},
'underscore': {
exports: '_'
}
}
})
requirejs(['bbn'], function(Backbone){
console.log(Backbone)
});
You will see that Underscore is being loaded, but since it is not defined as the correct module RequireJS just treats it as a regular JS file and does not receive a return value
source to share