Skip to content
This repository was archived by the owner on Nov 27, 2018. It is now read-only.

Adding Pre Compilers

laktek edited this page Nov 8, 2012 · 7 revisions

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).

How to add a custom pre-compiler

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.

Clone this wiki locally