【问题标题】:How to resolve a require string within a custom webpack loader如何在自定义 webpack 加载器中解析 require 字符串
【发布时间】:2015-09-03 18:42:45
【问题描述】:

我正在为 webpack 编写一个自定义加载器。

在我的加载器中,我有一个这样的要求字符串:

"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

【问题讨论】:

  • 你能描述一下整个任务吗?为什么你的加载器需要一个外部模块?

标签: javascript webpack


【解决方案1】:

有一个(到目前为止)未记录的方法:

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

此方法将在调用回调之前加载模块并应用所有加载器。

【讨论】:

    猜你喜欢
    • 2022-01-13
    • 2017-07-14
    • 2017-10-13
    • 1970-01-01
    • 2016-06-04
    • 2018-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多