使用 webpack 加载 requirejs 模块的 css 依赖

Load requirejs module's css dependency with webpack

我正在使用 webpack and I need to include some libraries built for requirejs。 一切正常,直到其中一个库声明 css dependency:

define(["css!./stylesheet.css"], function(){ \* module *\ });

Webpack 有一个 css loader too, however it does not load them automatically as requirejs's one does. One must pipe the css loader to the style loader 可以这样做:

require("style!css!./stylesheet.css");

有什么办法可以让之前的工作正常吗?例如,我可以覆盖这个特定库的 css 加载器,以便它使用样式加载器进行管道传输吗?

我使用 postLoaders 找到了一个不错的解决方案。

添加

postLoaders: [
  { test: /\.css$/, loader: 'style', include: path.join(__dirname, "pathTo/theLib") }
]

进入 webpack 配置的 module 属性 就成功了。