modularjs-compiler

DEPRECATED! Build a ModularJS package starting with a main module and consolidating all required modules into a single file.

npm install modularjs-compiler
48 downloads in the last month

DEPRECATED!

I am no longer mantaining this package and the github repo has been removed.

ModularJS Compiler

Build a ModularJS "pack" starting with a main module and consolidating all required modules into a single file which can be loaded via the ModularJS data-pack attribute on the modular.js script tag.

For use with the ModularJS browser utility. http://bluejeansandrain.github.com/modularjs/

Installation

https://npmjs.org/package/modularjs-compiler

npm install modularjs-compiler -g

Using as a command line utility

modularjs [options] main-module-id [extra-modules ...]

Options:
  -r, --root     The virtual root. Defaults to the working directory.
  -p, --paths    A list top-level module paths, space separated.
  -c, --config   A JSON encoded configuration file.
  -o, --output   Output package text to a file instead of standard out.
  -u, --uglify   Use UglifyJS to compress source. [boolean]
  -v, --verbose  Print extra info to standard error. [boolean]
  -h, --help     Print this usage text. [boolean]

The virtual root should be equivalent to the explicit or implicit virtual root used in the modular.js script tag.

Absolute and relative module paths are relative to the virtual root.

If no paths are specified, top-level module IDs will be resolved in the virtual root.

Extra modules can be manually included by specifying module IDs at the end of the argument list after the main-module-id.

Using as a NodeJS module

var modularjs = require( 'modularjs-compiler' );

modularjs.compile({

    // The virtual root should be equivalent to the explicit or implicit
    // virtual root used in the modular.js script tag.
    //
    // Optional. Defaults to the current working directory.
    root: "foo",

    // The list of paths in which to look for top-level module IDs. These
    // should usually be identical to those used in the modular.js script
    // tag. Absolute and relative module paths are relative to the virtual
    // root. An array or space seperated string is accepted.
    //
    // Optional. If no paths are specified, top-level module IDs will be
    // resolved in the virtual root.
    paths: ["lib", "node_modules"],
    // Alternatively:
    //  paths: "lib node_modules",

    // The ID of the main module. This can also be passed as the second
    // argument to this method instead of being included in the options.
    //
    // Required. This module will be included in the pack and all modules
    // it requires will be determines recursively and also included in the
    // pack.
    main: "main",

    // Extra modules IDs can be included in the pack by listing their IDs.
    // This can be an array or space separated string.
    //
    // This forces the compiler to "discover" that these modules have been
    // required. This might for instance be useful if you use a variable
    // instead of a string literal to require a module and the compiler
    // does not successfully detect it.
    //
    // If relative module IDs are used, they will be resolved relative to
    // the virtual root.
    //
    // Optional.
    extra: ["foo", "bar"],
    // Alternatives:
    //  extra: "foo bar",

    // Use UglifyJS to compress all required source files.
    //
    // Optional. Defaults to false.
    uglify: true,

    // If you are not serving your modules from the file system, or if your
    // virtual host configuration does not directly map to the local file
    // system, you may need to use a custom resolver.
    //
    // Your resolver will be passed the required _absolute_ module ID and a
    // "resolve" callback method that _must_ be called on success or
    // failure.
    //
    // "this" is also set to an object with the absolute root, absolute
    // top-level module paths, and the uri of the file that would have been
    // used without a custom resolver.
    //
    // If your resolver is unable to resolve the module it should call
    // resolve without any parameters. Otherwise it should call resolve
    // passing the source as the only argument.
    resolver: function( id, resolve )
    {
        // The virtual root path as given by the root option.
        this.root;

        // Top-level module paths resolved to file system absolutes. If no
        // paths were specified then this will default to an array
        // containing only the virtual root.
        this.paths;

        // The absolute path to the file that would have been used without
        // a custom resolver.
        this.uri;

        // Get the source any way you want.

        if ( <error> )
            resolve();
        else
            resolve( <source> );
    },

    // A callback to be called on compilation success or failure. On
    // failure, the err parameter will be non-null. On success, err will be
    // null and output will be a string.
    done: function( err, output )
    {
        // Do something with the error or output here.
    }
}, "main" /* Optional. Can also be given as the `main` option. */ )
.done( function( err, output )
{
    // Alternatively, compile returns a promise to which done handlers can
    // be bound rather than or in addition to the done property of the
    // options object.
});

The following helper methods which take an ID and return a boolean, are also exported.

  • isValidId
  • isAbsoluteId
  • isRelativeId
npm loves you