Skip to content

Commit

Permalink
feat: deep merge when rule is merge (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
burhanuday authored May 22, 2023
1 parent c658e19 commit ace52b2
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ function mergeWithRule({
throw new TypeError("Trying to merge non-objects");
}

// @ts-ignore: These should be objects now
ret[k] = { ...v, ...lastValue };
// deep merge
ret[k] = merge(v, lastValue);
break;
case CustomizeRule.Prepend:
if (!bMatches.length) {
Expand Down
76 changes: 75 additions & 1 deletion test/merge-with-rules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,80 @@ describe("Merge with rules", function () {
},
})(conf1, conf2)
).toEqual(expected);
})
});

it("should deep merge options", function () {
const base = {
module: {
rules: [
{
test: /\.scss$/,
use: [
{
loader: "css-loader",
options: {
modules: {
localIdentName: "[hash:base64]",
},
},
},
],
},
],
},
};
const development = {
module: {
rules: [
{
test: /\.scss$/,
use: [
{
loader: "css-loader",
options: {
modules: {
namedExport: true,
},
},
},
],
},
],
},
};
const result = {
module: {
rules: [
{
test: /\.scss$/,
use: [
{
loader: "css-loader",
options: {
modules: {
localIdentName: "[hash:base64]",
namedExport: true,
},
},
},
],
},
],
},
};

expect(
mergeWithRules({
module: {
rules: {
test: CustomizeRule.Match,
use: {
loader: CustomizeRule.Match,
options: CustomizeRule.Merge,
},
},
},
})(base, development)
).toEqual(result);
});
});

0 comments on commit ace52b2

Please sign in to comment.