Reputation: 547
How can I integrate requirejs in a meteor app and use AMD–modules, e.g for my Backbone modules? Has anybody done that and can tell me what steps are needed to get this working?
Upvotes: 11
Views: 3628
Reputation: 2460
Here is how I loaded Aloha Editor in Meteor and IronRouter. Aloha uses requirejs to load all its dependencies.
Add the following hook to your route:
onBeforeAction: function(pause)
{
// Dynamically load require.js
var one = IRLibLoader.load('/alohaeditor/lib/require.js',
{
success: function(){ console.log('Successfully loaded require.js'); },
error: function(){ console.log('Error loading require.js'); }
});
if(!one.ready())
return pause();
// Aloha settings
Aloha = window.Aloha || {};
Aloha.settings = Aloha.settings || {};
Aloha.settings.baseUrl = '/alohaeditor/lib/';
Aloha.settings.plugins = Aloha.settings.plugins || {};
Aloha.settings.plugins.load = 'common/ui, common/format, common/link, common/table, common/list, common/block, common/undo, common/contenthandler, common/paste, common/commands, common/abbr';
// Dynamically load aloha.js
var two = IRLibLoader.load('/alohaeditor/lib/aloha.js',
{
success: function(){ console.log('Successfully loaded aloha.js'); },
error: function(){ console.log('Error loading aloha.js'); }
});
if(!two.ready())
return pause();
},
Upvotes: 0
Reputation: 35725
One simple answer (though maybe not the one you're looking for) is that you can simply use the two independently. In other words, load all of your meteor scripts, then start your require-ified scripts loading. Your require-ified scripts will be able to use the Meteor stuff just fine, without having to "import" any of it in via Require's loader.
If you want to have to import it, you should instead create a Require "shim" for it.
Upvotes: 4