npm install homemadeinclude, exclude, define, put, if, elif, ifdef.#### a. Use in consolenode homemade.js path/to/source.js path/to/destination.js
#### b. Use with grunt ★
See grunt-homemade task.
Fully compatible with preprocessor.js syntax.
Source:
``js`
//#exclude
console.log(a, b, c)
//#end
Result:
`js`
Useful when you want to remove supporting code from the build, like helper functions etc.
Source:
`js`
//#include ./c.js
c.js:`js`
Hello world!
Result:
``
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.
Source:
`js`
//#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.
Source:
`jsvar a =
var projectName = //#put name
//#define a = {a:1, b:2, c:3}
//#put a;
//#put dictToArray(a);
//#put + projectName + ;`
Result:
`js`
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
Source:
`js`
//#if DEV
console.log("debug:", result)
//#else
//#put "var projectName = '" + name + "'"
//#endif
Result with DEV === true:`js`
console.log("debug:", result)
Result with DEV === false:`js`
var projectName = 'Hello world'
For more examples see test/before.js.
build.js:`jsvar pluginName =
(function($){
//#ifndef pluginName
var pluginName = "awesomePlugin"
//#else
/ #put + pluginName /
//#endif
//#include "../src/utils.js"
//#include "../src/AwesomePlugin.js"
//jquery-plugin
if ($){
$['fn'][pluginName] = function (arg) {
return this'each'{
var $e = $(e);
var instance = new AwesomePlugin($e[0], arg);
$e.data(pluginName, instance);
})
};
} else {
window[pluginName] = AwesomePlugin;
}
})(window['jQuery'] || window['Zepto']);
`
, 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`