greenish
greenish

Reputation: 1042

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

Upvotes: 3

Views: 1050

Answers (1)

greenish
greenish

Reputation: 1042

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.

Upvotes: 2

Related Questions