Skip to content Skip to sidebar Skip to footer

Using Babel To Convert Es6 Modules To Es5 Amd Modules, Not Working As Expected

I hope someone can help. I'm using grunt-babel to convert my ES6 module code to ES5 AMD module code. Here's my ES6 code: multiply.js export default function (x,y) { return x *

Solution 1:

After some further digging I finally realised where I went wrong.

In my current stack I'm forced to use Almond, instead of RequireJS. Because of this, Almond expects there to be a file to initialise the modules, hence why I was expecting Babel to generate one for me. But as it turns out, the code generated by Babel will work fine within RequireJS, but for it to work with Almond, I need to create a seperate es5 js file, just to initialise the files generated by Babel.

Something like this:

requirejs(['app'],
    function (app) {
        app();
    }
);

Post a Comment for "Using Babel To Convert Es6 Modules To Es5 Amd Modules, Not Working As Expected"