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

feat: deep merge when rule is merge #206

Merged
merged 1 commit into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});