Skip to content

Instantly share code, notes, and snippets.

@kapitancho
Created December 24, 2015 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kapitancho/15321bc580a3b2fcb835 to your computer and use it in GitHub Desktop.
Save kapitancho/15321bc580a3b2fcb835 to your computer and use it in GitHub Desktop.
RequireJS plugin for es6 + babel 6.
define(['module'], function (module) {
'use strict';
var fetchText = function(url, callback) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onreadystatechange = function(evt) {
if (xhr.readyState === 4) {
callback(xhr.responseText);
}
};
xhr.send(null);
};
return {
load: function (name, req, onload, config) {
var url = req.toUrl(name + '.js');
fetchText(url, function(text) {
try {
var code = Babel.transform(text, {
presets: ['es2015'],
plugins: ['transform-es2015-modules-amd']
}).code;
} catch (err) {
onload.error(err);
}
onload.fromText(code);
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment