question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

merging loaders and making plugins unique?

See original GitHub issue

OS: Win10 Node: v14.15.4

Hi there,

following the examples I have been able to merge my loaders by using mergeWithRules and I have also been able to test out mergeWithCustomize and customizeArray successfully.

However, I need to combine the two steps, as the configs I’m merging have different options for some of the plugin options.

Is this possible?

Looking at the source, I can see that mergeWithRules returns mergeWithCustomize but unable to figure out how to combine the two.

const mergedConfig = mergeWithRules(
  {
    module: {
      rules: {
        test: 'match',
        use: {
          loader: 'match',
          options: 'replace',
        },
      },
    },
  },
  { customizeArray: unique('plugins', ['HtmlWebpackPlugin'], plugin => plugin.constructor && plugin.constructor.name) }
)(commonConfig, cmsConfig, prodConfig);
module.exports = mergedConfig;

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
bebrawcommented, Feb 16, 2021

I’ve found it’s easier to solve these cases through composition as that avoids the problem altogether and keeps merge simple. I see you are using HtmlWebpackPlugin so what I would do is to have it included at the most specific configuration (i.e. specifically at dev/prod/…).

Can you share your current configuration so I can propose how you could solve it this way?

0reactions
b3nk3commented, Feb 17, 2021

It’s rather complex and I’d have to do some redactions haha.

Instead, I have sorted it based on your idea. 😃

It’s modular and only uses merge();

Thanks for your help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use the webpack-merge.unique function in ...
To help you get started, we've selected a few webpack-merge.unique examples, ... Plugin) => plugin.constructor && plugin.constructor.name ) }) //make it a ...
Read more >
Merging two module.rules just appends · Issue #146
To work, it would have to perform a merge over module.rules while making sure test: /\.css$/ is unique and merges loader while treating...
Read more >
Using webpack-merge to prepend loaders to a rules ...
While splitting up my webpack config, I have forgotten to include the MiniCssExtractPlugin in the plugins section of my prod. config file.
Read more >
webpack-merge
webpack-merge provides a merge function that concatenates arrays and merges objects creating a new object. If functions are encountered, ...
Read more >
Composing Configuration
This arrangement can make it faster to find configuration related to a category. Additionally, it can also reduce your build time if you're...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found