amd, require.js javascript example please
jeacott opened this issue · 4 comments
jeacott commented
Hi, I'd love an example or wiki entry that explains how to use this component with requirejs, or to have an amd compatible version out of the box. is it possible?
alekseykulikov commented
Hi, it is not for now. Added as feature for next release.
maxfi commented
@jeacott You can shim backbone.offline when using require.js. You should set out your require.config as below:
require.config({
baseUrl: 'scripts',
paths:{
'jquery': 'vendor/jquery/jquery',
'underscore': 'vendor/underscore/underscore', // amd fork
'backbone': 'vendor/backbone/backbone', // amd fork
'backbone.offline': 'vendor/backbone/backbone.offline'
},
shim:{
// This is the important line for you. It tells require.js that backbone.offline depends on backbone.
'backbone.offline': ['backbone']
}
});
You'll likely also want to use the AMD forks of backbone and underscore which can be found at https://github.com/amdjs
alekseykulikov commented
HI @maxfi, thank you for great introduction to require.js. I think shim part should looks so, but I'm not sure about exports
:
shim: {
'backbone.offline': ['backbone', 'underscore', 'jquery']
exports: 'Offline'
}
I will test it and then add to docs for next release.