concat-define
provides an implementation of AMD's define
function that concatenates modules into a single module that can be loaded using AMD or directly into the global context.
internal.js
define(function () {
function Internal() {
this.hello = function() {
return "Hello world.";
};
}
return Internal;
});
public.js
define(["./internal"], function Public(Internal) {
return {
public : new Internal().hello()
}
});
The two modules above combine to give the following output:
(function(factory) {
if (typeof define === "function" && define.amd) {
define([], factory);
} else if (typeof module === "object" && module.exports) {
module.exports = factory();
} else {
factory(this);
}
})(function(context) {
context = context || {};
var internal = (function () {
function Internal() {
this.hello = function() {
return "Hello world.";
};
}
return Internal;
})();
context.Public = (function (Internal) {
return {
public : new Internal().hello()
}
})(internal);
return context;
});