There isn't a One True Way, because every AMD project is different (some people wrap Backbone in a define
function, some use a shim
config, everyone organises things into different folder structures...). Basically, though, the adaptor needs to run in a lexical scope that has both Ractive
and Backbone
.
So one way to approach it would be to create a simple wrapper module like so:
define(["ractive","backbone"], function (Ractive, Backbone) {
// adaptor code goes here. No need to include the outer IIFE
// (https://github.com/Rich-Harris/Ractive/blob/master/plugins/adaptors/Backbone.js)
});
Then, you can either continue doing
define(["ractive","ractive.backbone"], function(Ractive) {....});
for each module that uses both Ractive and the Backbone adaptor, or you can require the Backbone adaptor once at the start of your app - as long as it's required before Ractive renders anything, it will work:
// in main.js, or equivalent
require(["app","ractive.backbone"], function (app) {
app.init(); // or whatever
});
Am open to suggestions as to how to make this whole thing a bit more self-explanatory!