What is PackagingJS

PackagingJS (a descendant of my earlier PackageJS compiler) is a compiling tool for bundling JS code and dependencies. It has a similar role to things such as CommonJS and RequireJS, but takes a very different approach that mimics the ES4 concepts of tying dependencies, namespacing, and filenames/file structure into one system that makes code extremely modular and shareable.

Where can I see it?

The PackagingJS compiler is published as an npm both as a normal module for usage in general Node.js work as well as a module made specifically for usage with gulp. You can find them both on the npm website via the buttons below:

 

PackagingJS (packagingjs) Gulp PackagingJS (gulp-packagingjs)

 


What does the code look like?

The basic principles of PackagingJS are the ES4 one file per “class” concept (with a loose interpretation of many types of modular code constituting a class) with the namespace of the class reflecting the architecture of the files (i.e. my.namespace.ClassName would be in the location my/namespace/ClassName.js). The code for that “class” might look something like this:

package my.namespace
{
    import my.namespace.OtherClass;

    function ClassName(param)
    {
        this.prop = OtherClass.property;
        this.foo = 'bar';
    }

    ClassName.prototype.methodName = function()
    {
        return  this.prop + this.foo;
    }
}

or in more ES6 form:

package my.namespace
{
    import my.namespace.OtherClass;

    class ClassName
    {
        constructor(param)
        {
            this.prop = OtherClass.property;
            this.foo = 'bar';
        }

        methodName()
        {
            return  this.prop + this.foo;
        }
    }
}

Basically each class is contained in a package statement which determines its namespace (if there is one) and above the class definition you can use things like import (and a couple other statements covered in the documentation) to bring in other classes for use. These things allow the PackagingJS compiler to compile any base class and all its dependencies into a single file of usable javascript that can be run in the browser (or other JS environments).

The npm pages hold all the documentation for the modules. Since they’ll be updated regularly I don’t want to document much here. Visit the links above for documentation!