0
votes

I using requirejs to manage the javascript files in my project. However, there are some external libraries I want to use that do not adhere to the AMD format. A library I want to include is barba.js. How would this be done using the package loading feature of requirejs? Ideally I want to include a commonjs module without running a conversion tool.

2
Unless I'm missing something big here, barba.js does adhere to the AMD format, the first lines of the code try using different solutions such as exports and define. This means it should work just fine with requireJS.Salketer

2 Answers

1
votes

Barba doesn't use the CommonJS module format.

Barba uses the UMD (Universal Module Definition) module format. This means that it is compatible with both the AMD module loading (as used by RequireJS) and CommonJS module loading (as used by Node.js).

So, that means you can just include Barba - or any other module in UMD format - with RequireJS the same way you include an AMD module:

define([
  "barba/barba"
], function(Barba) {
  Barba.Pjax.start(); // You can use Barba here
});
0
votes

From requireJS doc.

define(function(require, exports, module) {
    //Put traditional CommonJS module content here
});

This should make everything alright for you. I'm really not sure if it's needed though.