Provides a JavaScript source file preprocessor, e.g. to build different versions of a library. It's for example used to
build ProtoBuf.js (its build
and main script are quite good examples).
Directives
Includes (always relative to the baseDirectory, defaults to "."):
...// #include "path/to/file.js"...
Static conditions:
// #ifdef FULLconsole.log("Including extension");// #include "path/to/extension.js"// #elseconsole.log("Not including extension");// #endif
Inverse static conditions:
// #ifndef FULLconsole.log("Not including extension");// #elseconsole.log("Including extension");// #include "path/to/extension.js"// #endif
var result = new Preprocessor( mainFileSource, baseDirectoryOrIncludes).process(defines);
with baseDirectoryOrIncludes being either a string containing the path to the base directory or an object of included
sources by filename. When running in a browser, only the later is supported.
node.js / CommonJS
var Preprocessor = require("preprocessor");var source = "..."; // e.g. through fs.readFilevar pp = new Preprocessor(source, ".");console.log(pp.process({ FULL: true}));
RequireJS / AMD
require(["/path/to/Preprocessor.js"], function(Preprocessor) { var source = "..."; // e.g. through fs.readFile / $.ajax var pp = new Preprocessor(source, "."); console.log(pp.process({ FULL: true }));});
Browser / shim
Note: To use the #include directive in the browser, do not specify the base directory but an object of included
sources by filename: