Refactor module id plugins to be independent
This commit is contained in:
parent
e979f1534e
commit
4d7b5b3b5e
|
@ -40,10 +40,7 @@ const compareLocations = require("./compareLocations");
|
|||
const Queue = require("./util/Queue");
|
||||
const Semaphore = require("./util/Semaphore");
|
||||
const SortableSet = require("./util/SortableSet");
|
||||
const {
|
||||
compareModulesByIndexOrIdentifier,
|
||||
compareModulesByIdOrIdentifier
|
||||
} = require("./util/comparators");
|
||||
const { compareModulesByIdOrIdentifier } = require("./util/comparators");
|
||||
const createHash = require("./util/createHash");
|
||||
|
||||
/** @typedef {import("webpack-sources").Source} Source */
|
||||
|
@ -261,10 +258,6 @@ class Compilation {
|
|||
/** @type {SyncHook<Module[], any>} */
|
||||
reviveModules: new SyncHook(["modules", "records"]),
|
||||
/** @type {SyncHook<Module[]>} */
|
||||
optimizeModuleOrder: new SyncHook(["modules"]),
|
||||
/** @type {SyncHook<Module[]>} */
|
||||
advancedOptimizeModuleOrder: new SyncHook(["modules"]),
|
||||
/** @type {SyncHook<Module[]>} */
|
||||
beforeModuleIds: new SyncHook(["modules"]),
|
||||
/** @type {SyncHook<Module[]>} */
|
||||
moduleIds: new SyncHook(["modules"]),
|
||||
|
@ -1121,11 +1114,8 @@ class Compilation {
|
|||
const shouldRecord = this.hooks.shouldRecord.call() !== false;
|
||||
|
||||
this.hooks.reviveModules.call(this.modules, this.records);
|
||||
this.hooks.optimizeModuleOrder.call(this.modules);
|
||||
this.hooks.advancedOptimizeModuleOrder.call(this.modules);
|
||||
this.hooks.beforeModuleIds.call(this.modules);
|
||||
this.hooks.moduleIds.call(this.modules);
|
||||
this.applyModuleIds();
|
||||
this.hooks.optimizeModuleIds.call(this.modules);
|
||||
this.hooks.afterOptimizeModuleIds.call(this.modules);
|
||||
|
||||
|
@ -1875,61 +1865,6 @@ class Compilation {
|
|||
}
|
||||
}
|
||||
|
||||
applyModuleIds() {
|
||||
const chunkGraph = this.chunkGraph;
|
||||
|
||||
const unusedIds = [];
|
||||
let nextFreeModuleId = 0;
|
||||
const usedIds = new Set();
|
||||
if (this.usedModuleIds) {
|
||||
for (const id of this.usedModuleIds) {
|
||||
usedIds.add(id);
|
||||
}
|
||||
}
|
||||
|
||||
const modules1 = this.modules;
|
||||
for (let indexModule1 = 0; indexModule1 < modules1.length; indexModule1++) {
|
||||
const module1 = modules1[indexModule1];
|
||||
const moduleId = chunkGraph.getModuleId(module1);
|
||||
if (moduleId !== null) {
|
||||
usedIds.add(moduleId);
|
||||
}
|
||||
}
|
||||
|
||||
if (usedIds.size > 0) {
|
||||
let usedIdMax = -1;
|
||||
for (const usedIdKey of usedIds) {
|
||||
if (typeof usedIdKey !== "number") {
|
||||
continue;
|
||||
}
|
||||
|
||||
usedIdMax = Math.max(usedIdMax, usedIdKey);
|
||||
}
|
||||
|
||||
let lengthFreeModules = (nextFreeModuleId = usedIdMax + 1);
|
||||
|
||||
while (lengthFreeModules--) {
|
||||
if (!usedIds.has(lengthFreeModules)) {
|
||||
unusedIds.push(lengthFreeModules);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const modules2 = this.modules;
|
||||
for (let indexModule2 = 0; indexModule2 < modules2.length; indexModule2++) {
|
||||
const module2 = modules2[indexModule2];
|
||||
// Module that are not in any chunk don't need ids
|
||||
if (chunkGraph.getNumberOfModuleChunks(module2) === 0) continue;
|
||||
if (chunkGraph.getModuleId(module2) === null) {
|
||||
if (unusedIds.length > 0) {
|
||||
chunkGraph.setModuleId(module2, unusedIds.pop());
|
||||
} else {
|
||||
chunkGraph.setModuleId(module2, nextFreeModuleId++);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
applyChunkIds() {
|
||||
/** @type {Set<number>} */
|
||||
const usedIds = new Set();
|
||||
|
|
|
@ -1,67 +0,0 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const RequestShortener = require("./RequestShortener");
|
||||
const createHash = require("./util/createHash");
|
||||
|
||||
const getHash = str => {
|
||||
const hash = createHash("md4");
|
||||
hash.update(str);
|
||||
return hash.digest("hex").substr(0, 4);
|
||||
};
|
||||
|
||||
class NamedModulesPlugin {
|
||||
constructor(options) {
|
||||
this.options = options || {};
|
||||
}
|
||||
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap("NamedModulesPlugin", compilation => {
|
||||
compilation.hooks.beforeModuleIds.tap("NamedModulesPlugin", modules => {
|
||||
const chunkGraph = compilation.chunkGraph;
|
||||
const namedModules = new Map();
|
||||
const context = this.options.context || compiler.options.context;
|
||||
|
||||
for (const module of modules) {
|
||||
let moduleId = chunkGraph.getModuleId(module);
|
||||
if (moduleId === null) {
|
||||
const id = module.libIdent({ context });
|
||||
if (id) {
|
||||
moduleId = id;
|
||||
chunkGraph.setModuleId(module, id);
|
||||
}
|
||||
}
|
||||
|
||||
if (moduleId !== null) {
|
||||
const namedModule = namedModules.get(moduleId);
|
||||
if (namedModule !== undefined) {
|
||||
namedModule.push(module);
|
||||
} else {
|
||||
namedModules.set(moduleId, [module]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const namedModule of namedModules.values()) {
|
||||
if (namedModule.length > 1) {
|
||||
for (const module of namedModule) {
|
||||
const requestShortener = new RequestShortener(context);
|
||||
chunkGraph.setModuleId(
|
||||
module,
|
||||
`${chunkGraph.getModuleId(module)}?${getHash(
|
||||
requestShortener.shorten(module.identifier())
|
||||
)}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = NamedModulesPlugin;
|
|
@ -1,43 +0,0 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Florent Cailhol @ooflorent
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
/** @typedef {import("./Module")} Module */
|
||||
|
||||
/**
|
||||
* @param {Module} a first module to sort by
|
||||
* @param {Module} b second module to sort by
|
||||
* @returns {-1|0|1} sort value
|
||||
*/
|
||||
const byIndexOrIdentifier = (a, b) => {
|
||||
if (a.index < b.index) return -1;
|
||||
if (a.index > b.index) return 1;
|
||||
const identA = a.identifier();
|
||||
const identB = b.identifier();
|
||||
if (identA < identB) return -1;
|
||||
if (identA > identB) return 1;
|
||||
return 0;
|
||||
};
|
||||
|
||||
class NaturalModuleIdsPlugin {
|
||||
/**
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap("NaturalModuleIdsPlugin", compilation => {
|
||||
compilation.hooks.optimizeModuleOrder.tap(
|
||||
"NaturalModuleIdsPlugin",
|
||||
modules => {
|
||||
modules.sort(byIndexOrIdentifier);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = NaturalModuleIdsPlugin;
|
|
@ -150,8 +150,6 @@ class ProgressPlugin {
|
|||
optimizeChunkModules: "chunk modules optimization",
|
||||
afterOptimizeChunkModules: "after chunk modules optimization",
|
||||
reviveModules: "module reviving",
|
||||
optimizeModuleOrder: "module order optimization",
|
||||
advancedOptimizeModuleOrder: "advanced module order optimization",
|
||||
beforeModuleIds: "before module ids",
|
||||
moduleIds: "module ids",
|
||||
optimizeModuleIds: "module id optimization",
|
||||
|
|
|
@ -42,21 +42,22 @@ const SystemPlugin = require("./dependencies/SystemPlugin");
|
|||
|
||||
const WarnNoModeSetPlugin = require("./WarnNoModeSetPlugin");
|
||||
|
||||
const HashedModuleIdsPlugin = require("./ids/HashedModuleIdsPlugin");
|
||||
const NamedModuleIdsPlugin = require("./ids/NamedModuleIdsPlugin");
|
||||
const NaturalModuleIdsPlugin = require("./ids/NaturalModuleIdsPlugin");
|
||||
const OccurrenceModuleIdsPlugin = require("./ids/OccurrenceModuleIdsPlugin");
|
||||
const NaturalChunkOrderPlugin = require("./optimize/NaturalChunkOrderPlugin");
|
||||
|
||||
const DefinePlugin = require("./DefinePlugin");
|
||||
const FlagDependencyExportsPlugin = require("./FlagDependencyExportsPlugin");
|
||||
const FlagDependencyUsagePlugin = require("./FlagDependencyUsagePlugin");
|
||||
const HashedModuleIdsPlugin = require("./HashedModuleIdsPlugin");
|
||||
const NamedChunksPlugin = require("./NamedChunksPlugin");
|
||||
const NamedModulesPlugin = require("./NamedModulesPlugin");
|
||||
const NaturalModuleIdsPlugin = require("./NaturalModuleIdsPlugin");
|
||||
const NoEmitOnErrorsPlugin = require("./NoEmitOnErrorsPlugin");
|
||||
const EnsureChunkConditionsPlugin = require("./optimize/EnsureChunkConditionsPlugin");
|
||||
const FlagIncludedChunksPlugin = require("./optimize/FlagIncludedChunksPlugin");
|
||||
const MergeDuplicateChunksPlugin = require("./optimize/MergeDuplicateChunksPlugin");
|
||||
const ModuleConcatenationPlugin = require("./optimize/ModuleConcatenationPlugin");
|
||||
const NaturalChunkOrderPlugin = require("./optimize/NaturalChunkOrderPlugin");
|
||||
const OccurrenceChunkOrderPlugin = require("./optimize/OccurrenceChunkOrderPlugin");
|
||||
const OccurrenceModuleOrderPlugin = require("./optimize/OccurrenceModuleOrderPlugin");
|
||||
const RemoveEmptyChunksPlugin = require("./optimize/RemoveEmptyChunksPlugin");
|
||||
const RemoveParentModulesPlugin = require("./optimize/RemoveParentModulesPlugin");
|
||||
const RuntimeChunkPlugin = require("./optimize/RuntimeChunkPlugin");
|
||||
|
@ -364,18 +365,18 @@ class WebpackOptionsApply extends OptionsApply {
|
|||
new NaturalModuleIdsPlugin().apply(compiler);
|
||||
break;
|
||||
case "named":
|
||||
new NamedModulesPlugin().apply(compiler);
|
||||
new NamedModuleIdsPlugin().apply(compiler);
|
||||
break;
|
||||
case "hashed":
|
||||
new HashedModuleIdsPlugin().apply(compiler);
|
||||
break;
|
||||
case "size":
|
||||
new OccurrenceModuleOrderPlugin({
|
||||
new OccurrenceModuleIdsPlugin({
|
||||
prioritiseInitial: true
|
||||
}).apply(compiler);
|
||||
break;
|
||||
case "total-size":
|
||||
new OccurrenceModuleOrderPlugin({
|
||||
new OccurrenceModuleIdsPlugin({
|
||||
prioritiseInitial: false
|
||||
}).apply(compiler);
|
||||
break;
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
"use strict";
|
||||
|
||||
const {
|
||||
compareModulesByIndex,
|
||||
compareModulesByIndex2
|
||||
compareModulesByIndexOrIdentifier,
|
||||
compareModulesByIndex2OrIdentifier
|
||||
} = require("../util/comparators");
|
||||
|
||||
/** @typedef {import("../Compiler")} Compiler */
|
||||
|
@ -43,10 +43,10 @@ class ChunkModuleIdRangePlugin {
|
|||
let cmpFn;
|
||||
switch (options.order) {
|
||||
case "index":
|
||||
cmpFn = compareModulesByIndex(moduleGraph);
|
||||
cmpFn = compareModulesByIndexOrIdentifier(moduleGraph);
|
||||
break;
|
||||
case "index2":
|
||||
cmpFn = compareModulesByIndex2(moduleGraph);
|
||||
cmpFn = compareModulesByIndex2OrIdentifier(moduleGraph);
|
||||
break;
|
||||
default:
|
||||
throw new Error(
|
||||
|
@ -55,9 +55,11 @@ class ChunkModuleIdRangePlugin {
|
|||
}
|
||||
chunkModules = chunkGraph.getOrderedChunkModules(chunk, cmpFn);
|
||||
} else {
|
||||
chunkModules = modules.filter(m => {
|
||||
return chunkGraph.isModuleInChunk(m, chunk);
|
||||
});
|
||||
chunkModules = modules
|
||||
.filter(m => {
|
||||
return chunkGraph.isModuleInChunk(m, chunk);
|
||||
})
|
||||
.sort(compareModulesByIndexOrIdentifier(moduleGraph));
|
||||
}
|
||||
|
||||
let currentId = options.start || 0;
|
|
@ -5,10 +5,10 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const createHash = require("./util/createHash");
|
||||
|
||||
const validateOptions = require("schema-utils");
|
||||
const schema = require("../schemas/plugins/HashedModuleIdsPlugin.json");
|
||||
const schema = require("../../schemas/plugins/HashedModuleIdsPlugin.json");
|
||||
const { compareModulesByIndexOrIdentifier } = require("../util/comparators");
|
||||
const createHash = require("../util/createHash");
|
||||
|
||||
class HashedModuleIdsPlugin {
|
||||
constructor(options) {
|
||||
|
@ -33,7 +33,10 @@ class HashedModuleIdsPlugin {
|
|||
"HashedModuleIdsPlugin",
|
||||
modules => {
|
||||
const chunkGraph = compilation.chunkGraph;
|
||||
for (const module of modules) {
|
||||
const modulesInNaturalOrder = Array.from(modules)
|
||||
.filter(m => chunkGraph.getNumberOfModuleChunks(m) > 0)
|
||||
.sort(compareModulesByIndexOrIdentifier(compilation.moduleGraph));
|
||||
for (const module of modulesInNaturalOrder) {
|
||||
if (chunkGraph.getModuleId(module) === null) {
|
||||
const id = module.libIdent({
|
||||
context: this.options.context || compiler.options.context
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const RequestShortener = require("../RequestShortener");
|
||||
const createHash = require("../util/createHash");
|
||||
|
||||
/** @typedef {import("../Compiler")} Compiler */
|
||||
/** @typedef {import("../Module")} Module */
|
||||
|
||||
const getHash = str => {
|
||||
const hash = createHash("md4");
|
||||
hash.update(str);
|
||||
return hash.digest("hex").substr(0, 4);
|
||||
};
|
||||
|
||||
class NamedModuleIdsPlugin {
|
||||
constructor(options) {
|
||||
this.options = options || {};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap("NamedModuleIdsPlugin", compilation => {
|
||||
compilation.hooks.beforeModuleIds.tap("NamedModuleIdsPlugin", modules => {
|
||||
const chunkGraph = compilation.chunkGraph;
|
||||
const context = this.options.context
|
||||
? this.options.context
|
||||
: compiler.context;
|
||||
const requestShortener = this.options.context
|
||||
? new RequestShortener(this.options.context)
|
||||
: compilation.requestShortener;
|
||||
|
||||
/** @type {Map<string, Module[]>} */
|
||||
const nameToModules = new Map();
|
||||
|
||||
for (const module of modules) {
|
||||
if (chunkGraph.getNumberOfModuleChunks(module) === 0) continue;
|
||||
const moduleId = chunkGraph.getModuleId(module);
|
||||
if (moduleId === null) {
|
||||
const id = module.libIdent({ context }) || "";
|
||||
let array = nameToModules.get(id);
|
||||
if (array === undefined) {
|
||||
array = [];
|
||||
nameToModules.set(id, array);
|
||||
}
|
||||
array.push(module);
|
||||
}
|
||||
}
|
||||
|
||||
for (const [id, modules] of nameToModules) {
|
||||
if (modules.length > 1 || !id) {
|
||||
for (const module of modules) {
|
||||
chunkGraph.setModuleId(
|
||||
module,
|
||||
`${id}?${getHash(
|
||||
requestShortener.shorten(module.identifier())
|
||||
)}`
|
||||
);
|
||||
}
|
||||
} else {
|
||||
chunkGraph.setModuleId(modules[0], id);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = NamedModuleIdsPlugin;
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Florent Cailhol @ooflorent
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const { compareModulesByIndexOrIdentifier } = require("../util/comparators");
|
||||
const assignAscendingIds = require("./assignAscendingIds");
|
||||
|
||||
/** @typedef {import("../Compiler")} Compiler */
|
||||
/** @typedef {import("../Module")} Module */
|
||||
|
||||
class NaturalModuleIdsPlugin {
|
||||
/**
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap("NaturalModuleIdsPlugin", compilation => {
|
||||
compilation.hooks.moduleIds.tap("NaturalModuleIdsPlugin", modules => {
|
||||
const modulesInNaturalOrder = Array.from(modules).sort(
|
||||
compareModulesByIndexOrIdentifier(compilation.moduleGraph)
|
||||
);
|
||||
assignAscendingIds(modulesInNaturalOrder, compilation);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = NaturalModuleIdsPlugin;
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
const validateOptions = require("schema-utils");
|
||||
const schema = require("../../schemas/plugins/optimize/OccurrenceOrderModuleIdsPlugin.json");
|
||||
const { compareModulesByIndexOrIdentifier } = require("../util/comparators");
|
||||
const assignAscendingIds = require("./assignAscendingIds");
|
||||
|
||||
/** @typedef {import("../Compiler")} Compiler */
|
||||
/** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
|
||||
|
@ -27,17 +29,21 @@ class OccurrenceOrderModuleIdsPlugin {
|
|||
"OccurrenceOrderModuleIdsPlugin",
|
||||
compilation => {
|
||||
const moduleGraph = compilation.moduleGraph;
|
||||
compilation.hooks.optimizeModuleOrder.tap(
|
||||
compilation.hooks.moduleIds.tap(
|
||||
"OccurrenceOrderModuleIdsPlugin",
|
||||
modules => {
|
||||
const chunkGraph = compilation.chunkGraph;
|
||||
|
||||
const modulesInOccurrenceOrder = Array.from(modules).filter(
|
||||
m => chunkGraph.getNumberOfModuleChunks(m) > 0
|
||||
);
|
||||
|
||||
const occursInInitialChunksMap = new Map();
|
||||
const occursInAllChunksMap = new Map();
|
||||
|
||||
const initialChunkChunkMap = new Map();
|
||||
const entryCountMap = new Map();
|
||||
for (const m of modules) {
|
||||
for (const m of modulesInOccurrenceOrder) {
|
||||
let initial = 0;
|
||||
let entry = 0;
|
||||
for (const c of chunkGraph.getModuleChunksIterable(m)) {
|
||||
|
@ -80,7 +86,7 @@ class OccurrenceOrderModuleIdsPlugin {
|
|||
};
|
||||
|
||||
if (prioritiseInitial) {
|
||||
for (const m of modules) {
|
||||
for (const m of modulesInOccurrenceOrder) {
|
||||
const result =
|
||||
moduleGraph
|
||||
.getIncomingConnections(m)
|
||||
|
@ -91,18 +97,19 @@ class OccurrenceOrderModuleIdsPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
const originalOrder = new Map();
|
||||
let i = 0;
|
||||
for (const m of modules) {
|
||||
const result =
|
||||
moduleGraph.getIncomingConnections(m).reduce(countOccurs, 0) +
|
||||
chunkGraph.getNumberOfModuleChunks(m) +
|
||||
entryCountMap.get(m);
|
||||
occursInAllChunksMap.set(m, result);
|
||||
originalOrder.set(m, i++);
|
||||
}
|
||||
|
||||
modules.sort((a, b) => {
|
||||
const naturalCompare = compareModulesByIndexOrIdentifier(
|
||||
compilation.moduleGraph
|
||||
);
|
||||
|
||||
modulesInOccurrenceOrder.sort((a, b) => {
|
||||
if (prioritiseInitial) {
|
||||
const aEntryOccurs = occursInInitialChunksMap.get(a);
|
||||
const bEntryOccurs = occursInInitialChunksMap.get(b);
|
||||
|
@ -113,10 +120,10 @@ class OccurrenceOrderModuleIdsPlugin {
|
|||
const bOccurs = occursInAllChunksMap.get(b);
|
||||
if (aOccurs > bOccurs) return -1;
|
||||
if (aOccurs < bOccurs) return 1;
|
||||
const orgA = originalOrder.get(a);
|
||||
const orgB = originalOrder.get(b);
|
||||
return orgA - orgB;
|
||||
return naturalCompare(a, b);
|
||||
});
|
||||
|
||||
assignAscendingIds(modulesInOccurrenceOrder, compilation);
|
||||
}
|
||||
);
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
module.exports = (modules, compilation) => {
|
||||
const chunkGraph = compilation.chunkGraph;
|
||||
|
||||
const usedIds = new Set();
|
||||
if (compilation.usedModuleIds) {
|
||||
for (const id of compilation.usedModuleIds) {
|
||||
usedIds.add(id);
|
||||
}
|
||||
}
|
||||
|
||||
for (const module of modules) {
|
||||
const moduleId = chunkGraph.getModuleId(module);
|
||||
if (moduleId !== null) {
|
||||
usedIds.add(moduleId);
|
||||
}
|
||||
}
|
||||
|
||||
let nextId = 0;
|
||||
if (usedIds.size > 0) {
|
||||
for (const module of modules) {
|
||||
if (chunkGraph.getNumberOfModuleChunks(module) === 0) continue;
|
||||
if (chunkGraph.getModuleId(module) === null) {
|
||||
while (usedIds.has(nextId)) nextId++;
|
||||
chunkGraph.setModuleId(module, nextId++);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (const module of modules) {
|
||||
if (chunkGraph.getNumberOfModuleChunks(module) === 0) continue;
|
||||
if (chunkGraph.getModuleId(module) === null) {
|
||||
chunkGraph.setModuleId(module, nextId++);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
|
@ -359,8 +359,7 @@ class ModuleConcatenationPlugin {
|
|||
});
|
||||
}
|
||||
// add concatenated module to the compilation
|
||||
const idx = compilation.modules.indexOf(rootModule);
|
||||
compilation.modules.splice(idx, 1, newModule);
|
||||
compilation.modules.push(newModule);
|
||||
}
|
||||
compilation.modules = compilation.modules.filter(
|
||||
m => !usedModules.has(m)
|
||||
|
|
|
@ -90,32 +90,17 @@ const compareNumbers = (a, b) => {
|
|||
* @param {Module} b module
|
||||
* @returns {-1|0|1} compare result
|
||||
*/
|
||||
const compareModulesByIndex = (moduleGraph, a, b) => {
|
||||
return compareNumbers(
|
||||
moduleGraph.getPreOrderIndex(a),
|
||||
moduleGraph.getPreOrderIndex(b)
|
||||
);
|
||||
};
|
||||
/** @type {ParamizedComparator<ModuleGraph, Module>} */
|
||||
exports.compareModulesByIndex = createCachedParamizedComparator(
|
||||
compareModulesByIndex
|
||||
);
|
||||
|
||||
/**
|
||||
* @param {ModuleGraph} moduleGraph the module graph
|
||||
* @param {Module} a module
|
||||
* @param {Module} b module
|
||||
* @returns {-1|0|1} compare result
|
||||
*/
|
||||
const compareModulesByIndex2 = (moduleGraph, a, b) => {
|
||||
return compareNumbers(
|
||||
const compareModulesByIndex2OrIdentifier = (moduleGraph, a, b) => {
|
||||
const cmp = compareNumbers(
|
||||
moduleGraph.getPostOrderIndex(a),
|
||||
moduleGraph.getPostOrderIndex(b)
|
||||
);
|
||||
if (cmp !== 0) return cmp;
|
||||
return compareIds(a.identifier(), b.identifier());
|
||||
};
|
||||
/** @type {ParamizedComparator<ModuleGraph, Module>} */
|
||||
exports.compareModulesByIndex2 = createCachedParamizedComparator(
|
||||
compareModulesByIndex2
|
||||
exports.compareModulesByIndex2OrIdentifier = createCachedParamizedComparator(
|
||||
compareModulesByIndex2OrIdentifier
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -125,13 +110,12 @@ exports.compareModulesByIndex2 = createCachedParamizedComparator(
|
|||
* @returns {-1|0|1} compare result
|
||||
*/
|
||||
const compareModulesByIndexOrIdentifier = (moduleGraph, a, b) => {
|
||||
const cmp1 = compareNumbers(
|
||||
const cmp = compareNumbers(
|
||||
moduleGraph.getPreOrderIndex(a),
|
||||
moduleGraph.getPreOrderIndex(b)
|
||||
);
|
||||
if (cmp1 !== 0) return cmp1;
|
||||
const cmp2 = compareIds(a.identifier(), b.identifier());
|
||||
return cmp2;
|
||||
if (cmp !== 0) return cmp;
|
||||
return compareIds(a.identifier(), b.identifier());
|
||||
};
|
||||
/** @type {ParamizedComparator<ModuleGraph, Module>} */
|
||||
exports.compareModulesByIndexOrIdentifier = createCachedParamizedComparator(
|
||||
|
@ -145,10 +129,9 @@ exports.compareModulesByIndexOrIdentifier = createCachedParamizedComparator(
|
|||
* @returns {-1|0|1} compare result
|
||||
*/
|
||||
const compareModulesByIdOrIdentifier = (chunkGraph, a, b) => {
|
||||
const cmp1 = compareIds(chunkGraph.getModuleId(a), chunkGraph.getModuleId(b));
|
||||
if (cmp1 !== 0) return cmp1;
|
||||
const cmp2 = compareIds(a.identifier(), b.identifier());
|
||||
return cmp2;
|
||||
const cmp = compareIds(chunkGraph.getModuleId(a), chunkGraph.getModuleId(b));
|
||||
if (cmp !== 0) return cmp;
|
||||
return compareIds(a.identifier(), b.identifier());
|
||||
};
|
||||
/** @type {ParamizedComparator<ChunkGraph, Module>} */
|
||||
exports.compareModulesByIdOrIdentifier = createCachedParamizedComparator(
|
||||
|
|
|
@ -101,7 +101,6 @@ exportPlugins(exports, {
|
|||
EvalSourceMapDevToolPlugin: () => require("./EvalSourceMapDevToolPlugin"),
|
||||
ExtendedAPIPlugin: () => require("./ExtendedAPIPlugin"),
|
||||
ExternalsPlugin: () => require("./ExternalsPlugin"),
|
||||
HashedModuleIdsPlugin: () => require("./HashedModuleIdsPlugin"),
|
||||
HotModuleReplacementPlugin: () => require("./HotModuleReplacementPlugin"),
|
||||
IgnorePlugin: () => require("./IgnorePlugin"),
|
||||
LibraryTemplatePlugin: () => require("./LibraryTemplatePlugin"),
|
||||
|
@ -111,7 +110,6 @@ exportPlugins(exports, {
|
|||
Module: () => require("./Module"),
|
||||
ModuleFilenameHelpers: () => require("./ModuleFilenameHelpers"),
|
||||
NamedChunksPlugin: () => require("./NamedChunksPlugin"),
|
||||
NamedModulesPlugin: () => require("./NamedModulesPlugin"),
|
||||
NoEmitOnErrorsPlugin: () => require("./NoEmitOnErrorsPlugin"),
|
||||
NormalModuleReplacementPlugin: () =>
|
||||
require("./NormalModuleReplacementPlugin"),
|
||||
|
@ -132,18 +130,21 @@ exportPlugins(exports, {
|
|||
exportPlugins((exports.dependencies = {}), {
|
||||
DependencyReference: () => require("./dependencies/DependencyReference")
|
||||
});
|
||||
exportPlugins((exports.ids = {}), {
|
||||
ChunkModuleIdRangePlugin: () => require("./ids/ChunkModuleIdRangePlugin"),
|
||||
NaturalModuleIdsPlugin: () => require("./ids/NaturalModuleIdsPlugin"),
|
||||
OccurrenceModuleIdsPlugin: () => require("./ids/OccurrenceModuleIdsPlugin"),
|
||||
NamedModuleIdsPlugin: () => require("./ids/NamedModuleIdsPlugin"),
|
||||
HashedModuleIdsPlugin: () => require("./ids/HashedModuleIdsPlugin")
|
||||
});
|
||||
exportPlugins((exports.optimize = {}), {
|
||||
AggressiveMergingPlugin: () => require("./optimize/AggressiveMergingPlugin"),
|
||||
AggressiveSplittingPlugin: () =>
|
||||
require("./optimize/AggressiveSplittingPlugin"),
|
||||
ChunkModuleIdRangePlugin: () =>
|
||||
require("./optimize/ChunkModuleIdRangePlugin"),
|
||||
LimitChunkCountPlugin: () => require("./optimize/LimitChunkCountPlugin"),
|
||||
MinChunkSizePlugin: () => require("./optimize/MinChunkSizePlugin"),
|
||||
ModuleConcatenationPlugin: () =>
|
||||
require("./optimize/ModuleConcatenationPlugin"),
|
||||
OccurrenceModuleOrderPlugin: () =>
|
||||
require("./optimize/OccurrenceModuleOrderPlugin"),
|
||||
OccurrenceChunkOrderPlugin: () =>
|
||||
require("./optimize/OccurrenceChunkOrderPlugin"),
|
||||
RuntimeChunkPlugin: () => require("./optimize/RuntimeChunkPlugin"),
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
const { describeCases } = require("./TestCases.template");
|
||||
const webpack = require("../lib/webpack");
|
||||
|
||||
describe("TestCases", () => {
|
||||
describeCases({
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
const { describeCases } = require("./TestCases.template");
|
||||
const webpack = require("../lib/webpack");
|
||||
|
||||
describe("TestCases", () => {
|
||||
describeCases({
|
||||
|
|
|
@ -5,7 +5,7 @@ module.exports = [
|
|||
moduleIds: false
|
||||
},
|
||||
plugins: [
|
||||
new webpack.HashedModuleIdsPlugin({
|
||||
new webpack.ids.HashedModuleIdsPlugin({
|
||||
hashDigestLength: 2
|
||||
})
|
||||
]
|
||||
|
@ -15,7 +15,7 @@ module.exports = [
|
|||
moduleIds: false
|
||||
},
|
||||
plugins: [
|
||||
new webpack.HashedModuleIdsPlugin({
|
||||
new webpack.ids.HashedModuleIdsPlugin({
|
||||
hashDigest: "hex",
|
||||
hashDigestLength: 2
|
||||
})
|
||||
|
@ -26,7 +26,7 @@ module.exports = [
|
|||
moduleIds: false
|
||||
},
|
||||
plugins: [
|
||||
new webpack.HashedModuleIdsPlugin({
|
||||
new webpack.ids.HashedModuleIdsPlugin({
|
||||
hashFunction: "sha1",
|
||||
hashDigestLength: 3
|
||||
})
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
var webpack = require("../../../../");
|
||||
module.exports = {
|
||||
optimization: {
|
||||
moduleIds: "named",
|
||||
|
|
|
@ -7,12 +7,12 @@ module.exports = {
|
|||
main2: "./main2"
|
||||
},
|
||||
plugins: [
|
||||
new webpack.optimize.ChunkModuleIdRangePlugin({
|
||||
new webpack.ids.ChunkModuleIdRangePlugin({
|
||||
name: "main1",
|
||||
start: 100,
|
||||
end: 102
|
||||
}),
|
||||
new webpack.optimize.ChunkModuleIdRangePlugin({
|
||||
new webpack.ids.ChunkModuleIdRangePlugin({
|
||||
name: "main2",
|
||||
order: "index2"
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue