Skip to content

Commit bda8d52

Browse files
committed
Added chunkFilenameDelimiter option for SplitChunksPlugin: Applied requested changes
1 parent 085d288 commit bda8d52

File tree

7 files changed

+28
-1359
lines changed

7 files changed

+28
-1359
lines changed

lib/WebpackOptionsDefaulter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
210210
this.set("optimization.splitChunks.minSize", 30000);
211211
this.set("optimization.splitChunks.minChunks", 1);
212212
this.set("optimization.splitChunks.maxAsyncRequests", 5);
213-
this.set("optimization.splitChunks.chunkFilenameDelimiter", "~");
213+
this.set("optimization.splitChunks.automaticNameDelimiter", "~");
214214
this.set("optimization.splitChunks.maxInitialRequests", 3);
215215
this.set("optimization.splitChunks.name", true);
216216
this.set("optimization.splitChunks.cacheGroups", {});

lib/optimize/SplitChunksPlugin.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ module.exports = class SplitChunksPlugin {
8484
}
8585

8686
static normalizeOptions(options = {}) {
87-
const chunkFilenameDelimiter = options.chunkFilenameDelimiter || "~";
88-
8987
return {
9088
chunks: options.chunks || "all",
9189
minSize: options.minSize || 0,
@@ -94,51 +92,50 @@ module.exports = class SplitChunksPlugin {
9492
maxInitialRequests: options.maxInitialRequests || 1,
9593
getName:
9694
SplitChunksPlugin.normalizeName({
97-
option: options.name,
98-
chunkFilenameDelimiter
95+
name: options.name,
96+
automaticNameDelimiter: options.automaticNameDelimiter
9997
}) || (() => {}),
10098
filename: options.filename || undefined,
10199
getCacheGroups: SplitChunksPlugin.normalizeCacheGroups({
102100
cacheGroups: options.cacheGroups,
103-
chunkFilenameDelimiter
104-
}),
105-
chunkFilenameDelimiter: chunkFilenameDelimiter
101+
automaticNameDelimiter: options.automaticNameDelimiter
102+
})
106103
};
107104
}
108105

109-
static normalizeName({ option, chunkFilenameDelimiter }) {
110-
if (option === true) {
106+
static normalizeName({ name, automaticNameDelimiter }) {
107+
if (name === true) {
111108
const fn = (module, chunks, cacheGroup) => {
112109
const names = chunks.map(c => c.name);
113110
if (!names.every(Boolean)) return;
114111
names.sort();
115112
let name =
116113
(cacheGroup && cacheGroup !== "default"
117-
? cacheGroup + chunkFilenameDelimiter
118-
: "") + names.join(chunkFilenameDelimiter);
114+
? cacheGroup + automaticNameDelimiter
115+
: "") + names.join(automaticNameDelimiter);
119116
// Filenames and paths can't be too long otherwise an
120117
// ENAMETOOLONG error is raised. If the generated name if too
121118
// long, it is truncated and a hash is appended. The limit has
122119
// been set to 100 to prevent `[name].[chunkhash].[ext]` from
123120
// generating a 256+ character string.
124121
if (name.length > 100) {
125122
name =
126-
name.slice(0, 100) + chunkFilenameDelimiter + hashFilename(name);
123+
name.slice(0, 100) + automaticNameDelimiter + hashFilename(name);
127124
}
128125
return name;
129126
};
130127
return fn;
131128
}
132129
if (typeof option === "string") {
133130
const fn = () => {
134-
return option;
131+
return name;
135132
};
136133
return fn;
137134
}
138-
if (typeof option === "function") return option;
135+
if (typeof option === "function") return name;
139136
}
140137

141-
static normalizeCacheGroups({ cacheGroups, chunkFilenameDelimiter }) {
138+
static normalizeCacheGroups({ cacheGroups, automaticNameDelimiter }) {
142139
if (typeof cacheGroups === "function") {
143140
return cacheGroups;
144141
}
@@ -174,8 +171,8 @@ module.exports = class SplitChunksPlugin {
174171
key: key,
175172
priority: option.priority,
176173
getName: SplitChunksPlugin.normalizeName({
177-
option: option.name,
178-
chunkFilenameDelimiter
174+
name: option.name,
175+
automaticNameDelimiter
179176
}),
180177
chunks: option.chunks,
181178
enforce: option.enforce,

schemas/WebpackOptions.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,8 +1382,8 @@
13821382
"type": "string",
13831383
"minLength": 1
13841384
},
1385-
"chunkFilenameDelimiter": {
1386-
"description": "Sets the filename delimiter for created chunks",
1385+
"automaticNameDelimiter": {
1386+
"description": "Sets the name delimiter for created chunks",
13871387
"type": "string",
13881388
"minLength": 1
13891389
},

0 commit comments

Comments
 (0)