JavaScript Make Tool
Introduction
This tool is a JavaScript (JS) project builder (aka. compiler and linker) and can be used to bundle multiple single JS files (aka. modules) in one bundled output file (fully self-contained). This file can be either executed as a standalone program or can be embedded in another JS application as a library using require('bundle')
.
The jc tool includes a code minifier (adapted from uglify) providing a high compression ratio. Alternatively (built-in minifier is slow), an external minifier jsmin
can be used. The C source is provided in the src
directory.
In contrast to uglify or any other compiler, jc creates a bundled project code file by using a main (top-level) file passed as the only file to the make tool. Jc creates a bundled program or library by executing the code performing a live build! Each imported module is recorded and the file content is finally embedded in the bundled output file.
Commonly modules are imported by using the require
function. Files to be embedded in the bundled file using jc must be imported by using special functions (Require
, RequireIf
, Import
) provided by the compiler. The module files are searched using the current working directory path, a specified top level path, or additional include paths. Include paths can be relative to the current working directory. The final code can still use require
calls but the files are not embedded.
Since there is no code analysis the program to be created must import all modules that should be embedded using Require
on module top-level. In the case there are conditional or deeper code imports (inside functions, e.g., if (cond) m=require("m")
) a pre-loading (only executed at build time) can be performed by using RequireIf
. Command line arguments can be passed to the project code (e.g., -- --version
) to ensure proper execution of the project code.
If the -lib
option is set, a bundled library is created (passing the module exports of the main file to the library file). Otherwise, a standalone JS executable file is created that can be directly executed from command line (assuming node
is installed on the system).
Project build options can be provided by command line arguments or by providing one single JSON make file.
Although there is no traditional source code compiling the source code must be valid JS syntax. Basically ECMAScript 5 is supported, but this depends on the JS VM used to execute jc and the final program. Note that the built-in minifier performs syntax checking and only supports ECMAScript 5 (and versions below).
Download
- Github
- JavaScript Make Tool