webpack-merge icon indicating copy to clipboard operation
webpack-merge copied to clipboard

mergeWithRules appears to disregard loader match if test matches

Open molly-hayes opened this issue 4 years ago • 3 comments

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!

molly-hayes avatar Aug 04 '21 21:08 molly-hayes

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 avatar Aug 05 '21 07:08 bebraw

@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.

molly-hayes avatar Aug 05 '21 15:08 molly-hayes

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.

bebraw avatar Aug 05 '21 15:08 bebraw

Changing include: CustomizeRule.Append to include: CustomizeRule.Match should fix this issue. Not a bug

burhanuday avatar Jun 21 '23 14:06 burhanuday

Thanks, let's close.

bebraw avatar Jun 21 '23 15:06 bebraw