webpack-merge
webpack-merge copied to clipboard
mergeWithRules appears to disregard loader match if test matches
We noticed that two of our loader rules were combined that should not have been combined based on the CustomizeRules we provided. The test does match but the loader does not and is for some reason appended. It is almost as if the test is the only thing checked and then everything else is just combined regardless.
Here is a simplified example of what we are seeing:
const configA = {
module: {
rules: [
{
test: /\.(j|t)sx?$/,
use: [{
loader: 'null-loader',
}],
include: [
'package1',
'package2',
],
},
],
},
}
const configB = {
module: {
rules: [
{
test: /\.(j|t)sx?$/,
use: [{
loader: 'babel-loader',
options: {
envName: 'native',
},
}],
include: [
'package3',
'package4',
],
},
],
},
}
const rules = {
module: {
rules: {
test: CustomizeRule.Match,
use: {
loader: CustomizeRule.Match,
},
include: CustomizeRule.Append,
},
},
}
mergeWithRules(rules)(configA, configB)
// actual
module: {
rules: [
{
test: /\\.(j|t)sx?$/,
use: [
{
loader: 'null-loader',
},
{
loader: 'babel-loader',
options: {
envName: 'native',
},
},
],
include: [
'package1',
'package2',
'package3',
'package4',
]
}
]
}
// expected
module: {
rules: [
{
test: /\.(j|t)sx?$/,
use: [{
loader: 'null-loader',
}],
include: [
'package1',
'package2',
],
},
{
test: /\.(j|t)sx?$/,
use: [{
loader: 'babel-loader',
options: {
envName: 'native',
},
}],
include: [
'package3',
'package4',
]
}
]
}
Thank you in advance for your help!
Would it be possible for your dev team to send a patch? The project is unfunded right now so I cannot guarantee a fast turnaround on this one.
@bebraw we are going to try out writing our own customize function, I'll make sure to update this thread if we find something that works.
Ok, cool.
In my personal work, I use always the basic merge and solve configurations through composition as it's easy to reason.
On 5. Aug 2021, at 18.20, molly-hayes @.***> wrote:
@bebraw we are going to try out writing our own customize function, I'll make sure to update this thread if we find something that works.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.
Changing include: CustomizeRule.Append to include: CustomizeRule.Match should fix this issue. Not a bug
Thanks, let's close.