Skip to content

Commit 0e88e8a

Browse files
authored
Merge pull request webpack#6954 from webpack/fix/ChunkModuleIdRangePlugin
Use compilation instead of this in ChunkModuleIdRangePlugin
2 parents 397f51f + b715475 commit 0e88e8a

File tree

11 files changed

+88
-14
lines changed

11 files changed

+88
-14
lines changed

lib/optimize/ChunkModuleIdRangePlugin.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +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 => {
14-
const chunk = this.chunks.find(chunk => chunk.name === options.name);
15-
if (!chunk)
24+
const chunk = compilation.chunks.find(
25+
chunk => chunk.name === options.name
26+
);
27+
if (!chunk) {
1628
throw new Error(
17-
"ChunkModuleIdRangePlugin: Chunk with name '" +
18-
options.name +
19-
"' was not found"
29+
`ChunkModuleIdRangePlugin: Chunk with name '${
30+
options.name
31+
}"' was not found`
2032
);
21-
let currentId = options.start;
33+
}
34+
2235
let chunkModules;
2336
if (options.order) {
24-
chunkModules = chunk.modules.slice();
37+
chunkModules = Array.from(chunk.modulesIterable);
2538
switch (options.order) {
2639
case "index":
27-
chunkModules.sort((a, b) => {
28-
return a.index - b.index;
29-
});
40+
chunkModules.sort(sortByIndex);
3041
break;
3142
case "index2":
32-
chunkModules.sort((a, b) => {
33-
return a.index2 - b.index2;
34-
});
43+
chunkModules.sort(sortByIndex2);
3544
break;
3645
default:
3746
throw new Error(
@@ -40,10 +49,11 @@ class ChunkModuleIdRangePlugin {
4049
}
4150
} else {
4251
chunkModules = modules.filter(m => {
43-
return m.chunks.includes(chunk);
52+
return m.chunksIterable.has(chunk);
4453
});
4554
}
4655

56+
let currentId = options.start || 0;
4757
for (let i = 0; i < chunkModules.length; i++) {
4858
const m = chunkModules[i];
4959
if (m.id === null) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default "a";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default "b";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default "c";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default "d";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default "e";
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Hash: 27b68d27e07b42624dae
2+
Time: Xms
3+
Built at: Thu Jan 01 1970 00:00:00 GMT
4+
Asset Size Chunks Chunk Names
5+
main2.js 3.89 KiB 0 [emitted] main2
6+
main1.js 3.89 KiB 1 [emitted] main1
7+
Entrypoint main1 = main1.js
8+
Entrypoint main2 = main2.js
9+
chunk {0} main2.js (main2) 136 bytes [entry] [rendered]
10+
> ./main2 main2
11+
[0] ./e.js 20 bytes {0} [built]
12+
[1] ./f.js 20 bytes {0} [built]
13+
[2] ./main2.js 56 bytes {0} [built]
14+
[100] ./d.js 20 bytes {0} {1} [built]
15+
[101] ./a.js 20 bytes {0} {1} [built]
16+
chunk {1} main1.js (main1) 136 bytes [entry] [rendered]
17+
> ./main1 main1
18+
[3] ./b.js 20 bytes {1} [built]
19+
[4] ./main1.js 56 bytes {1} [built]
20+
[100] ./d.js 20 bytes {0} {1} [built]
21+
[101] ./a.js 20 bytes {0} {1} [built]
22+
[102] ./c.js 20 bytes {1} [built]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default "f";
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import "./a";
2+
import "./b";
3+
import "./c";
4+
import "./d";
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import "./a";
2+
import "./d";
3+
import "./e";
4+
import "./f";

0 commit comments

Comments
 (0)