merging loaders and making plugins unique?
See original GitHub issueOS: 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:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I’ve found it’s easier to solve these cases through composition as that avoids the problem altogether and keeps
mergesimple. I see you are usingHtmlWebpackPluginso 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?
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.