Adding Minifiers

KenanY edited this page Feb 3, 2013 · 4 revisions

When creating asset bundles, Punch will minify the CSS and JS files using CSSMin and Uglify.JS. If you want, you can also use any other minifier, by writing a wrapper for it.

Use this template to implement a custom minifier:

module.exports = {
    input_extensions: [".js"],

    minify: function(input, callback){
        var self = this;
        var output, err;

        // call the minifier

        return callback(err, output);

Custom minifier should implement a minify function, which takes in an input and a callback. After compilation is done, the callback should be invoked with the output (or an error).

How to add a custom minifier

To use a custom minifier in a project, you have to define it as a plugin in project's configuration (config.json).

	"plugins": {
		"parsers": {
			".css": "custom_minifer" 

The key should be the output extension of the files that are being minified (for example, if your minifier outputs in CSS, the key should be .css). Minifier should be specified as a valid Node.js module path.