Skip to content
Grzegorz Pabian edited this page Jan 8, 2015 · 3 revisions

Overview

Pre-processors are plugins used to process a file's content when it's read for the first time. These can be used to alter a file's content e.g. by instrumenting the code like code coverage tools do or compile a CoffeScript code to JavaScript.

Structure

A typical pre-processor should expose a process function. For more advanced builders you can use attach and init API - check Structure of a plugin section for more details.

Example:

module.exports = {
    name: 'bender-preporcessor-example',

    process: function (file) {

        // alter a file's content, i.e. compile the code or wrap it with some functions

        return file;
    }
};

The process function should return a received file object or a promise for this object if a part of the pre-processors's code works asynchronously.

The promise should be compatible with Promises/A+ specification.

In case you're looking for a good example of a pre-processor plugin, please check benderjs-coverage plugin.

File object

A file object is passed to the process function.

It contains multiple information about a file:

  • String path - path to a file
  • String content - file content
  • String mime - file mime type, used e.g. in HTTP headers
  • Number mtime - last file modification timestamp

Warning: Please avoid altering other properties than content unless you're 100% sure you know what you're doing.

Clone this wiki locally