Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Cozy JS preprocessor, supporting include, define, put and conditions.

branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

homemade.js Homemade.js

Cozy C-like preprocessor. Implements include, exclude, define, put, if, elif, ifdef.

a. Use in console

node homemade.js path/to/source.js path/to/destination.js

b. Use with grunt ★

See grunt-homemade task.


Fully compatible with preprocessor.js syntax.

#exclude — removes fragments of code


console.log(a, b, c)


Useful when you want to remove supporting code from the build, like helper functions etc.

#include — inserts file


//#include ./c.js


Hello world!


Hello world!

Files are inserted in a recursive way, so that inserted files will be handled also. The current directory . is taken one of the current file. The current file is that where the current #inline directive is.

#define — defines variable to use in preprocessor


//#define name = "Hello world"
//#define dictToArray = function(dict){ var result = []; for (var key in dict){ result.push(key + " " + dict[key]) }; return result; }

Defined variables can be used later in #put or #ifs.

#put — places variable source (uses tosource for serialization)


var projectName = //#put name
//#define a = {a:1, b:2, c:3}
//#put a;
//#put dictToArray(a);
//#put `var a = ` + projectName + `;`


var projectName = 'Hello world'
{a:1, b:2, c:3}
["a 1", "b 2", "c 3"]

To output raw code, use markdown inline code notation, like \raw code` + variable`

#if, #ifdef, #ifndef, #elif, #else


//#if DEV
    console.log("debug:", result)
    //#put "var projectName = '" + name + "'"

Result with DEV === true:

    console.log("debug:", result)

Result with DEV === false:

    var projectName = 'Hello world'

For more examples see test/before.js.

jQuery/Zepto/vanilla plugin boilerplate


    //#ifndef pluginName
        var pluginName = "awesomePlugin"
        /* #put `var pluginName = ` + pluginName */

    //#include "../src/utils.js"
    //#include "../src/AwesomePlugin.js"

    if ($){
        $['fn'][pluginName] = function (arg) {
            return this['each'](function(i,e){
                var $e = $(e);
                var instance = new AwesomePlugin($e[0], arg);
                $, instance);
    } else {
        window[pluginName] = AwesomePlugin;
})(window['jQuery'] || window['Zepto']);


This plugin was created as a fast replacement to preprocessor.js and alike, due to lack of necessary building features in them on that moment, like define, put etc.

For now homemade has some flaws:

  • Insecure − context is defined in global scope, so that you have to beware of variable names in #define
  • Nested conditions are not supported
  • No decent syntax errors detection

Projects which use homemade


Copyright Dmitry Ivanov. Written by Dmitry Ivanov. Licensed under the MIT license.

Something went wrong with that request. Please try again.