Skip to content

Commit 36d576c

Browse files
committed
Update ChunkModuleIdRangePlugin to webpack 4 API
1 parent b8b95cf commit 36d576c

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

lib/optimize/ChunkModuleIdRangePlugin.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,44 @@
33
Author Tobias Koppers @sokra
44
*/
55
"use strict";
6+
7+
const sortByIndex = (a, b) => {
8+
return a.index - b.index;
9+
};
10+
11+
const sortByIndex2 = (a, b) => {
12+
return a.index2 - b.index2;
13+
};
14+
615
class ChunkModuleIdRangePlugin {
716
constructor(options) {
817
this.options = options;
918
}
19+
1020
apply(compiler) {
1121
const options = this.options;
1222
compiler.hooks.compilation.tap("ChunkModuleIdRangePlugin", compilation => {
1323
compilation.hooks.moduleIds.tap("ChunkModuleIdRangePlugin", modules => {
1424
const chunk = compilation.chunks.find(
1525
chunk => chunk.name === options.name
1626
);
17-
if (!chunk)
27+
if (!chunk) {
1828
throw new Error(
19-
"ChunkModuleIdRangePlugin: Chunk with name '" +
20-
options.name +
21-
"' was not found"
29+
`ChunkModuleIdRangePlugin: Chunk with name '${
30+
options.name
31+
}"' was not found`
2232
);
23-
let currentId = options.start;
33+
}
34+
2435
let chunkModules;
2536
if (options.order) {
26-
chunkModules = chunk.modules.slice();
37+
chunkModules = Array.from(chunk.modulesIterable);
2738
switch (options.order) {
2839
case "index":
29-
chunkModules.sort((a, b) => {
30-
return a.index - b.index;
31-
});
40+
chunkModules.sort(sortByIndex);
3241
break;
3342
case "index2":
34-
chunkModules.sort((a, b) => {
35-
return a.index2 - b.index2;
36-
});
43+
chunkModules.sort(sortByIndex2);
3744
break;
3845
default:
3946
throw new Error(
@@ -42,10 +49,11 @@ class ChunkModuleIdRangePlugin {
4249
}
4350
} else {
4451
chunkModules = modules.filter(m => {
45-
return m.chunks.includes(chunk);
52+
return m.chunksIterable.has(chunk);
4653
});
4754
}
4855

56+
let currentId = options.start || 0;
4957
for (let i = 0; i < chunkModules.length; i++) {
5058
const m = chunkModules[i];
5159
if (m.id === null) {

0 commit comments

Comments
 (0)