如何解决自定义 webpack loader 中的 require 字符串

3

我是一名为webpack编写自定义加载器的开发者。

在我的加载器中,我有一个类似于这样的require字符串:

"css!less!./myFile.less"

有方法获取解析请求的输出吗?

我正在寻找模块应用所有加载器后的输出结果。换句话说:

如何从上述字符串中获取编译后的CSS?

我尝试在加载器上下文中使用 this.resolve

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?
});

但是我似乎无法获得解析后的输出。我可能做错了什么,我找到的有关此函数的唯一文档在这里:http://webpack.github.io/docs/loaders.html#resolve

请问您能描述一下整个任务吗?为什么您需要在加载器中使用外部模块? - Kreozot
1个回答

2

目前还没有记录的方法:

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

这种方法会在调用回调函数前加载模块并应用所有的加载器。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接