Skip to content

Commit

Permalink
fix: Fix rule merging without a match (#168)
Browse files Browse the repository at this point in the history
Closes #167.
  • Loading branch information
bebraw authored Dec 16, 2020
1 parent e71aef3 commit 7e8bd56
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ function mergeWithRule({
ret[k] = v.concat(appendValue);
break;
case CustomizeRule.Merge:
if (!bMatches.length) {
ret[k] = v;

break;
}

const lastValue = last(bMatches)[k];

if (!isPlainObject(v) || !isPlainObject(lastValue)) {
Expand Down
74 changes: 74 additions & 0 deletions test/merge-with-rules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1043,4 +1043,78 @@ describe("Merge with rules", function () {
})(base, development)
).toEqual(result);
});

it("should fall back to default behavior without a match when merging (#167)", function () {
const conf1 = {
module: {
rules: [
{
test: "/\\.scss$|\\.sass$/",
use: [
{
loader: "sass-loader",
options: {
sourceMap: true,
},
},
],
},
],
},
};
const conf2 = {
module: {
rules: [
{
test: "/\\.scss$|\\.sass$/",
use: [
{
loader: "sass-resources-loader",
options: {
resources: ["src/styles/includes.scss"],
},
},
],
},
],
},
};
const result = {
module: {
rules: [
{
test: "/\\.scss$|\\.sass$/",
use: [
{
loader: "sass-loader",
options: {
sourceMap: true,
},
},
{
loader: "sass-resources-loader",
options: {
resources: ["src/styles/includes.scss"],
},
},
],
},
],
},
};

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

0 comments on commit 7e8bd56

Please sign in to comment.