-
Notifications
You must be signed in to change notification settings - Fork 107
Adding Pre Compilers
Punch can pre-compile files written in CoffeeScript and Less. But you can easily add support to any other pre-compiler as well.
Following pre-compilers are already available as plugins:
If you want to write a custom pre-compiler follow these steps:
module.exports = {
input_extensions: [".less"],
compile: function(input, filename, callback){
var output;
// call the compiler with the input
return callback(err, output);
}
};
Custom pre-compiler should implement a compile
function, which takes in an input, filename (Punch will pass the name of the file that needs to be compiled) and a callback. After compilation is done, the callback should be invoked with the output (or an error).
To use a custom pre-compiler in a project, you have to define it as a plugin in project's configuration (config.json
).
"plugins": {
"compilers": {
".js": "custom_compiler"
}
}
The key should be the output extension of the compiled files (for example if your compiler reads CoffeeScript and outputs JS, key name should be .js
). Compiler should be specified as a valid Node.js module path.