Compiles JS source written as AMD modules to a single file without the need for a loader (RequireJS / almond / etc.)
$ git clone https://github.com/amitayh/amd-compiler.git
$ cd amd-compiler
$ npm install
Invoke the bin/compile
script to compile source:
$ node bin/compile <path/to/main> >> compiled.js
Say the given modules are defined in the path /foo/bar
:
// modA.js
define(["modB", "modC"], function(b, c) {
return b + c("A");
});
// modB.js
define(["modC"], function(c) {
return c("B");
});
// modC.js
define(function() {
return function(name) {
return "Hello, " + name + "!";
};
});
// main.js
require(["modA", "modB"], function(a, b) {
console.log(a, b);
});
Then invoking the comiler script like so:
$ node bin/compile /foo/bar/main
Will generate the following output:
(function () {
// Source: /foo/bar/modC.js
var modC = function () {
return function (name) {
return "Hello, " + name + "!";
};
}();
// Source: /foo/bar/modB.js
var modB = function (c) {
return c("B");
}(modC);
// Source: /foo/bar/modA.js
var modA = function (b, c) {
return b + c("A");
}(modB, modC);
// Source: /foo/bar/main.js
(function (a, b) {
console.log(a, b);
}(modA, modB));
}());
Install mocha:
$ npm install -g mocha
Run tests:
$ mocha specs/