Extra compilers for connect-compiler
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



Custom compilers for connect-compiler, which scratch my own itches -- specifically, a compiler to decorate files with the CommonJS machinery, and a simple YAML-to-JSON compiler.

Usage is the same as the connect-compiler middleware -- in fact, I recommend you substitute the compiler reference you get from connect-compiler-extras to ensure both modules point at the same middleware:

    var connect  = require('connect')
    ,   compiler = require('connect-compiler-extras')
    ,   server = connect.createServer(
                enabled : [ 'coffee', 'uglify' ],
                src     : 'src',
                dest    : 'var'
                enabled : 'commonjs',
                src     : ['src', 'var'],
                dest    : 'var',
                options : {
                    commonjs: { drop_path_parts:1 }
            connect.static(__dirname + '/public'),
            connect.static(__dirname + '/var')


Via npm, though I don't reliably publish it as nobody else cares.

git clone https://github.com/dsc/connect-compiler-extras.git
cd connect-compiler-extras
npm link

Use it in any other project by running the link in your project directory:

npm link connect-compiler-extras



ID: commonjs

Wraps JS modules in a CommonJS module definition.

Here's the itch: browserify and its ilk work poorly with Coco (often because they look explicitly for .js or .coffee files when doing module lookup, despite Coco properly handling the node import hook). Further, I prefer to send down each module as a separate file during development for ease of debugging (better stacks, esp). My solution is a CommonJSCompiler that handles requests for .mod.js by wrapping the appropriate .js file.

Using the compiler is straight-forward -- just request your files as .mod.js instead of .js. The wrapper assumes the require machinery and the require.install() function from the helper library are both on the page. I generally use the bootstrapper from browserify as well, which works great when when it comes down first.


  • drop_path_parts [default: 0] — Removes this many leading directory path parts. Let's say your JS modules have a deep and irrelevant path, like /~me/hacking/foo-app/static/js/foo/bar.mod.js for the module foo/bar. To avoid having to require with that ridiculous prefix, you'd use { drop_path_parts:5 } to drop the mountpoint (/~me/hacking/foo-app/static/js).
  • drop_full_ext [default: true] — Removes everything after the first dot in the basename, otherwise .mod(.min)?.js.
  • drop_pat [default: null] — Overrides the file-to-module pattern. If omitted, determined by drop_full_ext.


ID: pyyaml

A YAML-to-JSON compiler. No options; merely point your browser at a non-existent JSON file when it has a YAML counterpart. For example, requesting /data/options.json when only /data/options.yaml exists will compile the latter to the former. PyYamlCompiler obeys src and dest like every other connect-compiler.

If you happen to (somehow) have my python utility library installed, it will use the OrderedDict patch to preserve key order. This is not required; works fine without it.


Find a bug or want to contribute? Open a ticket on github. You're also welcome to send me email at dsc@less.ly.