diff --git a/lib/util/deterministicGrouping.js b/lib/util/deterministicGrouping.js index b30cc5cea..c6596f296 100644 --- a/lib/util/deterministicGrouping.js +++ b/lib/util/deterministicGrouping.js @@ -44,20 +44,30 @@ const similarity = (a, b) => { /** * @param {string} a key * @param {string} b key + * @param {Set} usedNames set of already used names * @returns {string} the common part and a single char for the difference */ -const getName = (a, b) => { +const getName = (a, b, usedNames) => { const l = Math.min(a.length, b.length); - let r = ""; - for (let i = 0; i < l; i++) { - const ca = a.charAt(i); - const cb = b.charAt(i); - r += ca; - if (ca === cb) { - continue; + let i = 0; + while (i < l) { + if (a.charCodeAt(i) !== b.charCodeAt(i)) { + i++; + break; } - return r; + i++; } + while (i < l) { + const name = a.slice(0, i); + const lowerName = name.toLowerCase(); + if (!usedNames.has(lowerName)) { + usedNames.add(lowerName); + return name; + } + i++; + } + // names always contain a hash, so this is always unique + // we don't need to check usedNames nor add it return a; }; @@ -391,12 +401,17 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => { }); // give every group a name + const usedNames = new Set(); for (let i = 0; i < result.length; i++) { const group = result[i]; - const first = group.nodes[0]; - const last = group.nodes[group.nodes.length - 1]; - let name = getName(first.key, last.key); - group.key = name; + if (group.nodes.length === 1) { + group.key = group.nodes[0].key; + } else { + const first = group.nodes[0]; + const last = group.nodes[group.nodes.length - 1]; + const name = getName(first.key, last.key, usedNames); + group.key = name; + } } // return the results diff --git a/test/configCases/split-chunks/max-size-casing/chunk.js b/test/configCases/split-chunks/max-size-casing/chunk.js new file mode 100644 index 000000000..e3866c0c1 --- /dev/null +++ b/test/configCases/split-chunks/max-size-casing/chunk.js @@ -0,0 +1,9 @@ +import a from "./file-a1"; +import b from "./file-b1"; +import A from "./file-A2"; +import B from "./file-B2"; +export default "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" + + a + + b + + A + + B; diff --git a/test/configCases/split-chunks/max-size-casing/file-A2.js b/test/configCases/split-chunks/max-size-casing/file-A2.js new file mode 100644 index 000000000..befaa887e --- /dev/null +++ b/test/configCases/split-chunks/max-size-casing/file-A2.js @@ -0,0 +1 @@ +export default "A2222222222222222222222"; diff --git a/test/configCases/split-chunks/max-size-casing/file-B2.js b/test/configCases/split-chunks/max-size-casing/file-B2.js new file mode 100644 index 000000000..8f0106edc --- /dev/null +++ b/test/configCases/split-chunks/max-size-casing/file-B2.js @@ -0,0 +1 @@ +export default "B2222222222222222222222"; diff --git a/test/configCases/split-chunks/max-size-casing/file-a1.js b/test/configCases/split-chunks/max-size-casing/file-a1.js new file mode 100644 index 000000000..c0f085930 --- /dev/null +++ b/test/configCases/split-chunks/max-size-casing/file-a1.js @@ -0,0 +1 @@ +export default "a1111111111111111111111"; diff --git a/test/configCases/split-chunks/max-size-casing/file-b1.js b/test/configCases/split-chunks/max-size-casing/file-b1.js new file mode 100644 index 000000000..6627122b6 --- /dev/null +++ b/test/configCases/split-chunks/max-size-casing/file-b1.js @@ -0,0 +1 @@ +export default "b1111111111111111111111"; diff --git a/test/configCases/split-chunks/max-size-casing/index.js b/test/configCases/split-chunks/max-size-casing/index.js new file mode 100644 index 000000000..03c38ce45 --- /dev/null +++ b/test/configCases/split-chunks/max-size-casing/index.js @@ -0,0 +1,10 @@ +it("should ignore case insenstive chars when generating maxSize filenames", () => + import(/* webpackChunkName: "chunk" */ "./chunk").then( + ({ default: value }) => { + expect(value).toContain("a111"); + expect(value).toContain("b111"); + expect(value).toContain("A222"); + expect(value).toContain("B222"); + expect(value).toContain("cccc"); + } + )); diff --git a/test/configCases/split-chunks/max-size-casing/test.config.js b/test/configCases/split-chunks/max-size-casing/test.config.js new file mode 100644 index 000000000..2e3be0636 --- /dev/null +++ b/test/configCases/split-chunks/max-size-casing/test.config.js @@ -0,0 +1,5 @@ +module.exports = { + findBundle: function (i, options) { + return ["main.js"]; + } +}; diff --git a/test/configCases/split-chunks/max-size-casing/webpack.config.js b/test/configCases/split-chunks/max-size-casing/webpack.config.js new file mode 100644 index 000000000..beebf1574 --- /dev/null +++ b/test/configCases/split-chunks/max-size-casing/webpack.config.js @@ -0,0 +1,14 @@ +/** @type {import("../../../../").Configuration} */ +module.exports = { + output: { + filename: "[name].js" + }, + optimization: { + chunkIds: "named", + splitChunks: { + hidePathInfo: false, + minSize: 50, + maxSize: 100 + } + } +};