|
2 | 2 | MIT License http://www.opensource.org/licenses/mit-license.php |
3 | 3 | Author Tobias Koppers @sokra |
4 | 4 | */ |
5 | | -function EnsureChunkConditionsPlugin() {} |
6 | | -module.exports = EnsureChunkConditionsPlugin; |
| 5 | +"use strict"; |
| 6 | + |
| 7 | +class EnsureChunkConditionsPlugin { |
7 | 8 |
|
8 | | -EnsureChunkConditionsPlugin.prototype.apply = function(compiler) { |
9 | | - compiler.plugin("compilation", function(compilation) { |
10 | | - compilation.plugin(["optimize-chunks-basic", "optimize-extracted-chunks-basic"], function(chunks) { |
11 | | - var changed = false; |
12 | | - chunks.forEach(function(chunk) { |
13 | | - chunk.modules.slice().forEach(function(module) { |
14 | | - if(!module.chunkCondition) return; |
15 | | - if(!module.chunkCondition(chunk)) { |
16 | | - var usedChunks = module._EnsureChunkConditionsPlugin_usedChunks = (module._EnsureChunkConditionsPlugin_usedChunks || []).concat(chunk); |
17 | | - var newChunks = []; |
18 | | - chunk.parents.forEach(function(parent) { |
19 | | - if(usedChunks.indexOf(parent) < 0) { |
20 | | - parent.addModule(module); |
21 | | - newChunks.push(parent); |
22 | | - } |
23 | | - }); |
24 | | - module.rewriteChunkInReasons(chunk, newChunks); |
25 | | - chunk.removeModule(module); |
26 | | - changed = true; |
27 | | - } |
| 9 | + apply(compiler) { |
| 10 | + compiler.plugin("compilation", (compilation) => { |
| 11 | + compilation.plugin(["optimize-chunks-basic", "optimize-extracted-chunks-basic"], (chunks) => { |
| 12 | + let changed = false; |
| 13 | + chunks.forEach((chunk) => { |
| 14 | + chunk.modules.slice().forEach((module) => { |
| 15 | + if(!module.chunkCondition) return; |
| 16 | + if(!module.chunkCondition(chunk)) { |
| 17 | + const usedChunks = module._EnsureChunkConditionsPlugin_usedChunks = (module._EnsureChunkConditionsPlugin_usedChunks || []).concat(chunk); |
| 18 | + let newChunks = []; |
| 19 | + chunk.parents.forEach((parent) => { |
| 20 | + if(usedChunks.indexOf(parent) < 0) { |
| 21 | + parent.addModule(module); |
| 22 | + newChunks.push(parent); |
| 23 | + } |
| 24 | + }); |
| 25 | + module.rewriteChunkInReasons(chunk, newChunks); |
| 26 | + chunk.removeModule(module); |
| 27 | + changed = true; |
| 28 | + } |
| 29 | + }); |
28 | 30 | }); |
| 31 | + if(changed) return true; |
29 | 32 | }); |
30 | | - if(changed) return true; |
31 | 33 | }); |
32 | | - }); |
33 | | -}; |
| 34 | + } |
| 35 | +} |
| 36 | +module.exports = EnsureChunkConditionsPlugin; |
0 commit comments