Skip to content

Commit 61ce0f7

Browse files
committed
apply review feedback
1 parent cc1636f commit 61ce0f7

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

lib/optimize/CommonsChunkPlugin.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,12 @@ The available options are:
6464
You can however specify the name of the async chunk by passing the desired string as the \"async\" option.`);
6565
}
6666

67-
const chunkNames = options.name ? [options.name] : options.names;
67+
/**
68+
* Make sure this is either an array or undefined.
69+
* "name" can be a string and
70+
* "names" a string or an array
71+
*/
72+
const chunkNames = options.name || options.names ? [].concat(options.name || options.names) : undefined;
6873
return {
6974
chunkNames: chunkNames,
7075
filenameTemplate: options.filename,
@@ -172,16 +177,18 @@ You can however specify the name of the async chunk by passing the desired strin
172177
// we have specified chunk names
173178
if(chunkNames) {
174179
// map chunks by chunkName for quick access
175-
const optimizedChunkMap = allChunks.reduce((map, chunk) => {
176-
map.set(chunk.name, chunk);
180+
const allChunksNameMap = allChunks.reduce((map, chunk) => {
181+
if(chunk.name) {
182+
map.set(chunk.name, chunk);
183+
}
177184
return map;
178185
}, new Map());
179186

180187
// Ensure we have a chunk per specified chunk name.
181188
// Reuse existing chunks if possible
182189
return chunkNames.map(chunkName => {
183-
if(optimizedChunkMap.has(chunkName)) {
184-
return optimizedChunkMap.get(chunkName);
190+
if(allChunksNameMap.has(chunkName)) {
191+
return allChunksNameMap.get(chunkName);
185192
}
186193
// add the filtered chunks to the compilation
187194
return compilation.addChunk(chunkName);

0 commit comments

Comments
 (0)