css-modules / css-modules-require-hook

A require hook to compile CSS Modules in runtime
MIT License
484 stars 44 forks source link

Specify options for postcss-modules-parser #62

Closed jonathanglasmeyer closed 8 years ago

jonathanglasmeyer commented 8 years ago

I'd like to use https://github.com/gilt/postcss-less to handle less/css-modules files. This works when I modify the line 93 in lib/index.js as follows:

+ var lessParser = require('postcss-less').parse;

- var lazyResult = runner.process(source, assign({}, { from: filename }));
+ var lazyResult = runner.process(source, assign({}, { from: filename, parser: lessParser}));

It'd be nice to be able to hook into this options object from the public css-modules-require-hook API. What do you think?

mightyaleksey commented 8 years ago

Looks good for me. Since I doubt that anyone uses the to option I think I'll replace it with possibility to provide all options to the process function.

jonathanglasmeyer commented 8 years ago

Awesome. :)

mightyaleksey commented 8 years ago

I published the new version: 4.0.0. Check it out.

Small example:

const hook = require('css-modules-require-hook');
const lessParser = require('postcss-less').parse;

hook({
  extensions: '.less',
  processorOpts: {parser: lessParser},
});