Skip to content

Commit 3bacdce

Browse files
fix(config): let a minimize shorthand assigned in apply() replace the options
1 parent 567c9f0 commit 3bacdce

2 files changed

Lines changed: 29 additions & 6 deletions

File tree

‎lib/config/defaults.js‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2467,16 +2467,16 @@ const applyOptimizationDefaults = (
24672467
D(optimization, "portableRecords", records);
24682468
D(optimization, "realContentHash", production);
24692469
// A plugin can assign the object shorthand in `apply()`, which runs after
2470-
// normalization: fold it in here too, so `minimize` stays a boolean. The
2471-
// normalized type is already one, hence the cast.
2470+
// normalization: fold it in here too, so `minimize` stays a boolean. It
2471+
// replaces the configured options rather than defaulting them, as
2472+
// overwriting the resolved option always has. The normalized type is
2473+
// already a boolean, hence the cast.
24722474
const minimizeAssignedInApply = /** @type {unknown} */ (
24732475
optimization.minimize
24742476
);
24752477
if (typeof minimizeAssignedInApply === "object") {
2476-
F(
2477-
optimization,
2478-
"minimizeOptions",
2479-
() => /** @type {OptimizationMinimizeOptions} */ (minimizeAssignedInApply)
2478+
optimization.minimizeOptions = /** @type {OptimizationMinimizeOptions} */ (
2479+
minimizeAssignedInApply
24802480
);
24812481
optimization.minimize = true;
24822482
}

‎test/Defaults.unittest.js‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6089,4 +6089,27 @@ describe("optimization.minimize", () => {
60896089
html: false
60906090
});
60916091
});
6092+
6093+
it("should let a shorthand assigned after normalization replace the configured options", () => {
6094+
const { applyWebpackOptionsDefaults, getNormalizedWebpackOptions } =
6095+
require("..").config;
6096+
6097+
const normalized = getNormalizedWebpackOptions({
6098+
mode: "production",
6099+
optimization: { minimize: { css: false } }
6100+
});
6101+
6102+
// Assigning `optimization.minimize` in `apply()` replaces what the config
6103+
// named, as overwriting the resolved option always has.
6104+
normalized.optimization.minimize = /** @type {EXPECTED_ANY} */ ({
6105+
html: false
6106+
});
6107+
applyWebpackOptionsDefaults(normalized);
6108+
6109+
expect(normalized.optimization.minimize).toBe(true);
6110+
expect(normalized.optimization.minimizeOptions).toEqual({
6111+
...DEFAULT_MINIMIZE_OPTIONS,
6112+
html: false
6113+
});
6114+
});
60926115
});

0 commit comments

Comments
 (0)