concat-define
v0.9.1
Published
`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.
Downloads
9
Readme
concat-define
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.
Usage
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;
});