Skip to content

Commit c39c963

Browse files
authored
Merge pull request webpack#7284 from Connormiha/optimize-remove-empty-chunks
Optimize RemoveEmptyChunksPlugin
2 parents 9a72294 + 8d1d569 commit c39c963

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lib/optimize/RemoveEmptyChunksPlugin.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ class RemoveEmptyChunksPlugin {
88
apply(compiler) {
99
compiler.hooks.compilation.tap("RemoveEmptyChunksPlugin", compilation => {
1010
const handler = chunks => {
11-
chunks
12-
.filter(
13-
chunk =>
14-
chunk.isEmpty() && !chunk.hasRuntime() && !chunk.hasEntryModule()
15-
)
16-
.forEach(chunk => {
11+
for (let i = chunks.length - 1; i >= 0; i--) {
12+
const chunk = chunks[i];
13+
if (
14+
chunk.isEmpty() &&
15+
!chunk.hasRuntime() &&
16+
!chunk.hasEntryModule()
17+
) {
1718
chunk.remove("empty");
18-
chunks.splice(chunks.indexOf(chunk), 1);
19-
});
19+
chunks.splice(i, 1);
20+
}
21+
}
2022
};
2123
compilation.hooks.optimizeChunksBasic.tap(
2224
"RemoveEmptyChunksPlugin",

0 commit comments

Comments
 (0)