2

我正在使用 react-bootstrap 和 css 模块。在我的 webpack.config.js 中,我可以使用以下配置运行我的 bootstrap.css:

{ test: /\.css$/, loader: "style-loader!css-loader" }

但是我的 css 模块应该有这个设置:

{
    test: /\.css$/,
    loaders: [
        'style?sourceMap',
    'css?modules&importLoaders=1&localIdentName=[path]___[name]__[local]___[hash:base64:5]'
    ]
}

如何将它们结合起来以使其适用于 css 模块和 react-bootstrap

4

1 回答 1

2

您可以保留两个加载器:一个用于全局 CSS(如 Bootstrap),另一个用于CSS 模块

为了避免具有相同test属性的加载器之间发生冲突,请使用 webpack 的规则包含排除属性:

{
  test: /\.css$/,
  loader: "style-loader!css-loader",
  include: [
    /* Paths to Bootstrap and further global CSS only */
  ]
},
{
  test: /\.css$/,
  loaders: [
    'style?sourceMap',
    'css?modules&importLoaders=1&localIdentName[path]___[name]__[local]___[hash:base64:5]'
  ],
  include: [
    /* eg. Paths to your source directory  */
  ]
}
于 2017-05-07T23:31:34.410 回答