gpt4 book ai didi

webpack - 排除 webpack 加载器中的目录

转载 作者:行者123 更新时间:2023-12-04 02:22:34 24 4
gpt4 key购买 nike

我正在尝试在我的 webpack 项目中使用 css-modules,但我也在使用 node_modules 中的包中的一些 css .如何编写加载器以仅使用我的 module 中的模块目录而不是 node_modules目录?我尝试了以下方法,但它很糟糕。看起来它正在尝试将模块内容应用于 node_modules 中的 css .

  {
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')
]
},

最佳答案

对于那些现在发现这个的人(比如我),我通过定义互补的 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]'
}
}

当在两个加载器上编写没有排除规则的情况下,我从 webpack 得到一个编译错误。

关于webpack - 排除 webpack 加载器中的目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36458909/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com