How to implement Punch Autoprefixer pre-processor?

I would like to implement an autoprefixer preprocessor for a punch static node generator.

However, in the Punch language, I'm not sure if it will qualify as a compiler, minifier, etc. I tried all of the above to no avail.

Here is my most recent attempt to get something 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 someone direct me in the right direction?

+5
source share
1 answer

It seems that at the moment, punch compilers can only compile from another extension (for example, .mycss or .less ). Using this, you are almost there:

In module.exports , input_extensions: desired extension (not .css ) should be set, for example. [".mycss"] .

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

really strange since you are defining the same key twice. Delete the line punch-sass-compiler . If you want to call another compiler, just require its module in your compiler code, call another compiler and change the provided output to your liking.

Punch minifiers are not suitable for your purpose, as they only participate in production (with punch g ), and not in development.

+1
source

Source: https://habr.com/ru/post/1236284/


All Articles