Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use "mergeWithRules " merge multilevel configuration #153

Closed
23cicada opened this issue Oct 22, 2020 · 6 comments
Closed

How to use "mergeWithRules " merge multilevel configuration #153

23cicada opened this issue Oct 22, 2020 · 6 comments

Comments

@23cicada
Copy link

I want to merge the "modules " under the a and b files.

const a = {
  module: {
    rules: [
      {
        test: /\.(sa|sc|c)ss/,
        use: [
          {
            loader: 'css-loader',
            options: {
              importLoaders: 2,
              modules: { auto: true },
            }
          }
        ]
      }
    ]
  }
}

const b = {
  module: {
    rules: [
      {
        test: /\.(sa|sc|c)ss/,
        use: [
          {
            loader: 'css-loader',
            options: {
              modules: {
                localIdentName: '[hash:base64]'
              }
            }
          }
        ]
      }
    ]
  }
}

const mergeRules = mergeWithRules({
  module: {
    rules: {
      test: CustomizeRule.Match,
      use: {
        loader: CustomizeRule.Match,
        options: {
          modules: CustomizeRule.Append
        }
      }
    }
  }
})(a, b)

result:

{
  "module":
  {
    "rules":
    [
      {
        "test": {},
        "use": [
          {
            "loader": "css-loader",
            "options": {
              "importLoaders": 2,
              "modules": {"auto": true}
            }
          }
        ]
      }
    ]
  }
}

I don't think that's allowed. Is there another way?

@bebraw
Copy link
Member

bebraw commented Oct 22, 2020

Yeah, I see. It looks like I'll have to add a bit of extra code to support this use case. Thanks for bringing this up.

@23cicada
Copy link
Author

Yeah, I see. It looks like I'll have to add a bit of extra code to support this use case. Thanks for bringing this up.

I don't know if such a multi-level merger is in order.

@bebraw
Copy link
Member

bebraw commented Oct 22, 2020

@23cicada I mean, I need to add a bit of extra logic to cover for this use case. When I've done that, then your proposed configuration should work. 👍

@23cicada
Copy link
Author

@23cicada I mean, I need to add a bit of extra logic to cover for this use case. When I've done that, then your proposed configuration should work. 👍

Okay, thank you. Should I close this issue?

@bebraw
Copy link
Member

bebraw commented Oct 22, 2020

@23cicada Nope, please keep it open and I'll close once it works.

@bebraw bebraw closed this as completed in 7231d6c Dec 11, 2020
@bebraw
Copy link
Member

bebraw commented Dec 11, 2020

@23cicada It looks like this works as a side effect of the work on #151 and #159. I added a test to verify.

If you are using 5.5.0 or newer, it should work as you expect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants