我正在尝试在我的webpack项目中使用css-modules,但我也在使用包中的一些css node_modules
.如何编写一个加载器只使用我module
目录中的模块而不是目录中的模块node_modules
?我尝试了以下但它是borks.看起来它正试图将模块的东西应用到css中node_modules
.
{
test: /\.css$/,
loader: 'style!css-loader?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]',
include: [
path.resolve(__dirname, 'modules')
]
},
{
test: /\.css$/,
loader: 'style!css',
include: [
path.resolve(__dirname, 'node_modules')
]
},
Run Code Online (Sandbox Code Playgroud)
小智 5
exclude
对于那些现在发现这一点的人(像我一样),我通过在 webpack 配置中定义补充规则来实现这一点:
{
test: /\.css$/,
loader: 'css-loader',
exclude: /my_app_client_dir/,
query: {
modules: true,
localIdentName: '[local]' // no funny stuff with node_modules resources
}
},
{
test: /\.css$/,
exclude: /node_modules/,
loader: 'css-loader',
query: {
modules: true,
localIdentName: '[name]__[local]___[hash:base64:5]'
}
}
Run Code Online (Sandbox Code Playgroud)
当在两个加载器上没有排除规则的情况下编写此内容时,我从 webpack 中收到了编译错误。
sma*_*sma -1
您还可以排除 node_modules 目录:
{
test: /\.css$/,
loader: 'style!css',
exclude: /node_modules/,
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
22379 次 |
最近记录: |