diff --git a/src/index.ts b/src/index.ts index 26444ac..81fe684 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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) { diff --git a/test/merge-with-rules.test.ts b/test/merge-with-rules.test.ts index 4fa6699..0a52219 100644 --- a/test/merge-with-rules.test.ts +++ b/test/merge-with-rules.test.ts @@ -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); + }); });