我正在使用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
最佳答案
您可以保留两个加载器:一个用于全局 CSS(如 Bootstrap),另一个用于CSS 模块。
为了避免具有相同 test
属性的加载器之间发生冲突,请使用 webpack 的规则 include和 exclude属性:
{
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 */
]
}
关于reactjs - 在 webpack 中响应多个 css 加载器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43836563/