bmatcuk / brunch-static

Transform static files using brunch.
MIT License
10 stars 2 forks source link

Release

brunch-static

Transform static files using brunch.

Brunch is great for doing all sorts of transpiling, compiling, minifying, uglfying, combining, and other such activities on CSS and Javascript files. But what if you have a file that isn't CSS or Javascript (and doesn't transpile into those things), and you want to convert it into something else in your output? For example, maybe you don't want to write boring HTML when you could be using something more friendly (like jade). Brunch isn't really designed for that.

Enter brunch-static.

brunch-static is a plugin that makes it possible to write other plugins (called "processors") that can operate on files, outputting a "static" file (or files) in your output directory. Several brunch plugins attempt to solve this problem on their own, but they all suffer from some drawback. It is the aim of brunch-static to solve these problems, while making it easy to write a static plugin.

If you want to dive into writing your own processor, jump down. Otherwise, keep reading.

Installation

Install the plugin via npm with npm install --save-dev brunch-static

Or manually:

Configuration

brunch-static's only config is a list of processors you want. In your brunch-config.coffee, you can add your static processors:

exports.config =
  ...
  plugins:
    static:
      pathTransform: ((filename) -> ...)
      processors: [
        ...
      ]

Available Processors

Below is a list of available processors. If you'd like your processor to be included in this list, create an issue with your project's URL and a description.

Writing brunch-static Processors

What Does brunch-static Do?

Ok, so, first, what do you get with brunch-static?

  1. brunch-static will write your output file(s), taking care to create subdirectories as necessary.
  2. brunch-static will not add any output to the brunch output files.

Processors

Processors are kind of similar to Brunch plugins theselves: an object that has certain members and methods. It's recommended that your project follows the naming scheme: whatever-brunch-static to make it easy to find in npm.

var MyStaticProcessor = function(config) { ... };

MyStaticProcessor.prototype = {
  handles: ...,
  compile: function(data, filename, callback) { ... }
};

// export a simple function to make it easier to include in brunch-config.coffee
module.exports = function(config) { return new MyStaticProcessor(config); };