1234567891011121314151617181920212223242526272829303132333435363738394041 |
- "use strict";
- class NaturalChunkOrderPlugin {
-
- apply(compiler) {
- compiler.hooks.compilation.tap("NaturalChunkOrderPlugin", compilation => {
- compilation.hooks.optimizeChunkOrder.tap(
- "NaturalChunkOrderPlugin",
- chunks => {
- chunks.sort((chunkA, chunkB) => {
- const a = chunkA.modulesIterable[Symbol.iterator]();
- const b = chunkB.modulesIterable[Symbol.iterator]();
-
- while (true) {
- const aItem = a.next();
- const bItem = b.next();
- if (aItem.done && bItem.done) return 0;
- if (aItem.done) return -1;
- if (bItem.done) return 1;
- const aModuleId = aItem.value.id;
- const bModuleId = bItem.value.id;
- if (aModuleId < bModuleId) return -1;
- if (aModuleId > bModuleId) return 1;
- }
- });
- }
- );
- });
- }
- }
- module.exports = NaturalChunkOrderPlugin;
|