How to create addon

Matt Winchester edited this page Jun 30, 2014 · 12 revisions
Clone this wiki locally

Addons are often used to add specific engines support. See instructions below to create your own.


If you create addon package with standard interface, please add mincer-contrib to keywords of you package.json. That will help to search.

We strongly reccommend to provide this interface for init:

var Mincer = require('mincer');

Code example

Here is example of code, that adds JSX engine support:

'use strict';

// Second param is not mandatory, used only to force specific
// module version when nested dependencies cause conflict.
module.exports = function addJsxEngine(Mincer, jsx) {

  var JsxEngine = Mincer.JsxEngine = function JsxEngine() {
    Mincer.Template.apply(this, arguments);
    jsx = jsx || Mincer.Template.libs.jsx || require('react-tools');

  require('util').inherits(JsxEngine, Mincer.Template);

  JsxEngine.prototype.evaluate = function evaluate(/*context, locals*/) { = jsx.transform(;

     // If your engine provides source map, put it here
     // 1. If internal paths exists on source map, those must be RELATIVE to
     //    current asset folder. Usually, that's ok.
     // 2. Map propetry `sourceContent` must be filled. If not - fill manually.

     // = <your_sourcemap>

     // If your source can have dependencies, and engine can return
     // dependencies list, add pass path for automatic tracking.

     // context.dependOn(file1);
     // context.dependOn(file2);

  Mincer.registerEngine('.jsx', Mincer.JsxEngine);


You just need to create node.js package. See complete result.


  • don't forget to add with usage examples
  • for package.json
    • add mincer-contrib to keywords
    • add peerDependency if you need it
  • add tests if possible