profile
viewpoint

Ask questionsHow 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

I also asked this question on StackOverflow but didn't get any views: http://stackoverflow.com/questions/32383195/how-to-resolve-a-require-string-within-a-custom-webpack-loader

webpack/webpack

Answer questions mareksuscak

@mnpenner Whoa, it's a 3-year-old comment but as far as I remember, I did although I did not write my own loader in the end. I used string-replace-loader instead which was all I needed.

useful!

Related questions

Cannot statically analyse 'require(..., ...)' in line hot 3
webpack 4 dynamic import got exception in "(window.webpackJsonP = window.webpackJsonP || []).push" which "push" is not a function hot 2
webpack@4 - ERROR in TypeError: __webpack_require__(...) is not a function hot 2
"webpack not installed" in new project hot 1
Can you PLEASE improve the SplitChunksPlugin error message? hot 1
Error `Uncaught TypeError: util.inherits is not a function` hot 1
"Critical dependency: the request of a dependency is an expression" in iconv-loader.js hot 1
webpack keeps asking if I want to install webpack-cli hot 1
Uncaught TypeError: __webpack_require__(…).context is not a function hot 1
"@import directive requires a url or quoted path" hot 1
Unexpected end of JSON input while parsing near '...,"husky":"^3.0.2","is' hot 1
webpack 5 beta feedback hot 1
Module parse failed. Unexpected character '#'. hot 1
Critical dependency error when use react-loadable hot 1
webpack4: Error--Block-scoped declarations (let, const, function, class) not yet supported outside strict mode hot 1
Github User Rank List