Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve a require string within a custom webpack loader

I'm writing a custom loader for webpack.

Within my loader I've got a require string like this:

"css!less!./myFile.less"

Is there a way to get the output of the resolved request?

I'm looking for the output of the module after all loaders have been applied. Or in other words:

How do I get the compiled css from the string above?

I tried to use this.resolve on the loader context:

this.resolve(this.context, "css!less!./myFile.less", function(err, result){
     // Best case scenario so far: 
     // result == "./myFile.less"

     // How do I get the css from myFile.less here? 
     // Is that even possible/the right way to get this?
});

But I can't seem to get the resolved output. I'm probably doing something wrong, the only documentation I've found about this function is here: http://webpack.github.io/docs/loaders.html#resolve

like image 979
greenish Avatar asked Nov 28 '25 11:11

greenish


1 Answers

There is a (so far) undocumented method:

this.loadModule(request, callback:function(err, source));

This method will load the module and apply all loaders before calling the callback.

like image 82
greenish Avatar answered Nov 30 '25 02:11

greenish