Allow appending objects in `mergeWithRules`
See original GitHub issueConsider the following example:
const a = {
module: {
rules: [
{
test: /\.css$/,
use: [{ loader: "style-loader", options: { someOption: true } }, { loader: "sass-loader" }],
},
],
},
};
const b = {
module: {
rules: [
{
test: /\.css$/,
use: [
{
loader: "style-loader",
options: {
modules: true,
},
},
],
},
],
},
};
const result = {
module: {
rules: [
{
test: /\.css$/,
use: [
{
loader: "style-loader",
options: {
someOptions: true,
modules: true,
},
},
{ loader: "sass-loader" },
],
},
],
},
};
assert.deepStrictEqual(
mergeWithRules({
module: {
rules: {
test: "match",
use: {
loader: "match",
options: "append",
},
},
},
})(a, b),
result
);
Currently this will fail, since append only supports arrays. However, merging loaders options is a perfectly valid scenario and should be pretty easy to support.
Any chance we can get that?
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
webpack-merge | Yarn - Package Manager
webpack-merge provides a merge function that concatenates arrays and merges objects creating a new object. If functions are encountered, it will execute ...
Read more >webpack-merge/CHANGELOG.md - UNPKG
10, - Fix - Don't merge strings with objects in `mergeWithRules`. #172 ... 34, - Feat - Allow `mergeWithRules` to merge based on...
Read more >webpack-merge - npm
webpack-merge provides a merge function that concatenates arrays and merges objects creating a new object. If functions are encountered, ...
Read more >Merge nested objects in JavaScript, and append matching ...
This is a good opportunity to show off the neat javascript spread syntax, Array and Object prototype functions, and destructuring patterns.
Read more >create-single-spa
yarn add --dev webpack-config-single-spa webpack-merge ... modify the webpack config however you'd like to by adding to this object
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

Yeah, I can add a type check and throw for sure.
Yeah, I see what you mean now. I added simple type checks to guard against append/prepend/merge. I think that covers it well and now it’s easier to notice if you are trying to merge types that the system doesn’t expect.
If you notice missing checks, open separate issues with small test cases for them and I’ll add logic based on that.