Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I implement a Punch Autoprefixer Pre-Processor?

I'd like to implement an autoprefixer pre-processor for the Punch static site generator.

However, in Punch parlance, I'm not sure if this would qualify as a compiler, minifier, etc. I've tried all of the above to no avail.

Here's my most recent attempt at getting anything working:

./autoprefixer.js

module.exports = {
    input_extensions: [".css"],
    force_compile: true,
    compile: function(input, filename, callback){
        return callback(null, "*{color: red;}");
    }
};

config.json

...
    "plugins": {
        "compilers": {
            ".css": "punch-sass-compiler",
            ".css": "autoprefixer"
        }
    }
...

result

/home/peter/projects/website/node_modules/punch/lib/asset_bundler.js:62
                        if (compiler && compiler.input_extensions.indexOf(template_extension) > -1)
                                                                 ^
TypeError: Cannot read property 'indexOf' of undefined
  at /home/peter/projects/website/node_modules/punch/lib/asset_bundler.js:62:45
  at /home/peter/projects/website/node_modules/punch/lib/template_handler.js:119:11
  at fs.js:334:14
  at /home/peter/projects/website/node_modules/punch/node_modules/fstream/node_modules/graceful-fs/graceful-fs.js:42:10
  at FSReqWrap.oncomplete (fs.js:95:15)

Can anyone steer me in the right direction?

like image 264
pdoherty926 Avatar asked Nov 10 '22 01:11

pdoherty926


1 Answers

It seems that at the moment, punch compilers can only compile from a different extension (say .mycss or .less). Using that, you're almost there:

In module.exports, input_extensions: must be set to the extension you desire (not .css), e.g. [".mycss"].

"plugins": {
    "compilers": {
        ".css": "punch-sass-compiler",
        ".css": "autoprefixer"
    }
}

is really strange, since you're defining the same key twice. Delete the punch-sass-compiler line. If you want to invoke another compiler, simply require its module in your compiler's code, call the other compiler and modify the supplied output to your liking.

Punch minifiers are not suitable for your goal, since they only get involved in production (with punch g), not when developing.

like image 104
phihag Avatar answered Nov 14 '22 22:11

phihag