It\'s already possible to convert commonjs modules to requirejs, but I still want to know whether it\'s possible to do the reverse. Is there any way to convert requireJS modules
Manually, it should be possible.
A require.js module looks like:
define('module', ['dep1', 'dep2'], function(dep1, dep2) {
return myFunction = function() {
};
});
Exporting to a CommonJs module shouldn't be too hard:
var dep1 = require('dep1');
var dep2 = require('dep1');
exports.myFunction = function() {
};
You don't have to return a function, it can be an object too:
define('module', ['dep1', 'dep2'], function(dep1, dep2) {
return {
myFunction1: function() {
},
myFunction2: function() {
}
};
});
...
var dep1 = require('dep1');
var dep2 = require('dep1');
exports.myObject = {
myFunction1: function() {
},
myFunction2: function() {
}
};
Edit: converting is also possible.