-
Notifications
You must be signed in to change notification settings - Fork 100
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.
Here's how a custom pre-compiler should be implemented:
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 specify it in the project's configuration (config.json
) under plugins
.
"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.