mirror of https://github.com/webpack/webpack.git
Merge pull request #6355 from webpack/for_of_loops
Use for-of loops instead of forEach
This commit is contained in:
commit
d6816afddf
|
@ -35,44 +35,50 @@ class BannerPlugin {
|
||||||
apply(compiler) {
|
apply(compiler) {
|
||||||
const options = this.options;
|
const options = this.options;
|
||||||
const banner = this.banner;
|
const banner = this.banner;
|
||||||
|
const matchObject = ModuleFilenameHelpers.matchObject.bind(undefined, options);
|
||||||
|
|
||||||
compiler.hooks.compilation.tap("BannerPlugin", (compilation) => {
|
compiler.hooks.compilation.tap("BannerPlugin", (compilation) => {
|
||||||
compilation.hooks.optimizeChunkAssets.tap("BannerPlugin", (chunks) => {
|
compilation.hooks.optimizeChunkAssets.tap("BannerPlugin", (chunks) => {
|
||||||
chunks.forEach((chunk) => {
|
for(const chunk of chunks) {
|
||||||
if(options.entryOnly && !chunk.canBeInitial()) return;
|
if(options.entryOnly && !chunk.canBeInitial()) {
|
||||||
chunk.files
|
continue;
|
||||||
.filter(ModuleFilenameHelpers.matchObject.bind(undefined, options))
|
}
|
||||||
.forEach((file) => {
|
|
||||||
let basename;
|
|
||||||
let query = "";
|
|
||||||
let filename = file;
|
|
||||||
const hash = compilation.hash;
|
|
||||||
const querySplit = filename.indexOf("?");
|
|
||||||
|
|
||||||
if(querySplit >= 0) {
|
for(const file of chunk.files) {
|
||||||
query = filename.substr(querySplit);
|
if(!matchObject(file)) {
|
||||||
filename = filename.substr(0, querySplit);
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const lastSlashIndex = filename.lastIndexOf("/");
|
let basename;
|
||||||
|
let query = "";
|
||||||
|
let filename = file;
|
||||||
|
const hash = compilation.hash;
|
||||||
|
const querySplit = filename.indexOf("?");
|
||||||
|
|
||||||
if(lastSlashIndex === -1) {
|
if(querySplit >= 0) {
|
||||||
basename = filename;
|
query = filename.substr(querySplit);
|
||||||
} else {
|
filename = filename.substr(0, querySplit);
|
||||||
basename = filename.substr(lastSlashIndex + 1);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const comment = compilation.getPath(banner, {
|
const lastSlashIndex = filename.lastIndexOf("/");
|
||||||
hash,
|
|
||||||
chunk,
|
|
||||||
filename,
|
|
||||||
basename,
|
|
||||||
query,
|
|
||||||
});
|
|
||||||
|
|
||||||
return compilation.assets[file] = new ConcatSource(comment, "\n", compilation.assets[file]);
|
if(lastSlashIndex === -1) {
|
||||||
|
basename = filename;
|
||||||
|
} else {
|
||||||
|
basename = filename.substr(lastSlashIndex + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const comment = compilation.getPath(banner, {
|
||||||
|
hash,
|
||||||
|
chunk,
|
||||||
|
filename,
|
||||||
|
basename,
|
||||||
|
query,
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
compilation.assets[file] = new ConcatSource(comment, "\n", compilation.assets[file]);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,9 +24,9 @@ const sortByIdentifier = (a, b) => {
|
||||||
const getModulesIdent = set => {
|
const getModulesIdent = set => {
|
||||||
set.sort();
|
set.sort();
|
||||||
let str = "";
|
let str = "";
|
||||||
set.forEach(m => {
|
for(const m of set) {
|
||||||
str += m.identifier() + "#";
|
str += m.identifier() + "#";
|
||||||
});
|
}
|
||||||
return str;
|
return str;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -246,7 +246,9 @@ class Chunk {
|
||||||
hash.update(`${this.id} `);
|
hash.update(`${this.id} `);
|
||||||
hash.update(this.ids ? this.ids.join(",") : "");
|
hash.update(this.ids ? this.ids.join(",") : "");
|
||||||
hash.update(`${this.name || ""} `);
|
hash.update(`${this.name || ""} `);
|
||||||
this._modules.forEach(m => hash.update(m.hash));
|
for(const m of this._modules) {
|
||||||
|
hash.update(m.hash);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
canBeIntegrated(otherChunk) {
|
canBeIntegrated(otherChunk) {
|
||||||
|
|
|
@ -231,7 +231,7 @@ class ChunkGroup {
|
||||||
parentChunkGroup._children.delete(this);
|
parentChunkGroup._children.delete(this);
|
||||||
|
|
||||||
// cleanup "sub chunks"
|
// cleanup "sub chunks"
|
||||||
this._children.forEach(chunkGroup => {
|
for(const chunkGroup of this._children) {
|
||||||
/**
|
/**
|
||||||
* remove this chunk as "intermediary" and connect
|
* remove this chunk as "intermediary" and connect
|
||||||
* it "sub chunks" and parents directly
|
* it "sub chunks" and parents directly
|
||||||
|
@ -240,7 +240,7 @@ class ChunkGroup {
|
||||||
chunkGroup.addParent(parentChunkGroup);
|
chunkGroup.addParent(parentChunkGroup);
|
||||||
// add "sub chunk" to parent
|
// add "sub chunk" to parent
|
||||||
parentChunkGroup.addChild(chunkGroup);
|
parentChunkGroup.addChild(chunkGroup);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -270,8 +270,8 @@ class Compilation extends Tapable {
|
||||||
cacheModule.disconnect();
|
cacheModule.disconnect();
|
||||||
this._modules.set(identifier, cacheModule);
|
this._modules.set(identifier, cacheModule);
|
||||||
this.modules.push(cacheModule);
|
this.modules.push(cacheModule);
|
||||||
cacheModule.errors.forEach(err => this.errors.push(err));
|
for(const err of cacheModule.errors) this.errors.push(err);
|
||||||
cacheModule.warnings.forEach(err => this.warnings.push(err));
|
for(const err of cacheModule.warnings) this.warnings.push(err);
|
||||||
return {
|
return {
|
||||||
module: cacheModule,
|
module: cacheModule,
|
||||||
issuer: true,
|
issuer: true,
|
||||||
|
@ -323,7 +323,7 @@ class Compilation extends Tapable {
|
||||||
|
|
||||||
const callback = err => {
|
const callback = err => {
|
||||||
this._buildingModules.delete(module);
|
this._buildingModules.delete(module);
|
||||||
callbackList.forEach(cb => cb(err));
|
for(const cb of callbackList) cb(err);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.hooks.buildModule.call(module);
|
this.hooks.buildModule.call(module);
|
||||||
|
@ -691,7 +691,7 @@ class Compilation extends Tapable {
|
||||||
|
|
||||||
const callback = err => {
|
const callback = err => {
|
||||||
this._rebuildingModules.delete(module);
|
this._rebuildingModules.delete(module);
|
||||||
callbackList.forEach(cb => cb(err));
|
for(const cb of callbackList) cb(err);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.hooks.rebuildModule.call(module);
|
this.hooks.rebuildModule.call(module);
|
||||||
|
@ -737,7 +737,9 @@ class Compilation extends Tapable {
|
||||||
this.namedChunkGroups.clear();
|
this.namedChunkGroups.clear();
|
||||||
this.additionalChunkAssets.length = 0;
|
this.additionalChunkAssets.length = 0;
|
||||||
this.assets = {};
|
this.assets = {};
|
||||||
this.modules.forEach(module => module.unseal());
|
for(const module of this.modules) {
|
||||||
|
module.unseal();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
seal(callback) {
|
seal(callback) {
|
||||||
|
@ -750,7 +752,7 @@ class Compilation extends Tapable {
|
||||||
|
|
||||||
this.nextFreeModuleIndex = 0;
|
this.nextFreeModuleIndex = 0;
|
||||||
this.nextFreeModuleIndex2 = 0;
|
this.nextFreeModuleIndex2 = 0;
|
||||||
this._preparedEntrypoints.forEach(preparedEntrypoint => {
|
for(const preparedEntrypoint of this._preparedEntrypoints) {
|
||||||
const module = preparedEntrypoint.module;
|
const module = preparedEntrypoint.module;
|
||||||
const name = preparedEntrypoint.name;
|
const name = preparedEntrypoint.name;
|
||||||
const chunk = this.addChunk(name);
|
const chunk = this.addChunk(name);
|
||||||
|
@ -769,7 +771,7 @@ class Compilation extends Tapable {
|
||||||
|
|
||||||
this.assignIndex(module);
|
this.assignIndex(module);
|
||||||
this.assignDepth(module);
|
this.assignDepth(module);
|
||||||
});
|
}
|
||||||
this.processDependenciesBlocksForChunkGroups(this.chunkGroups);
|
this.processDependenciesBlocksForChunkGroups(this.chunkGroups);
|
||||||
this.sortModules(this.modules);
|
this.sortModules(this.modules);
|
||||||
this.hooks.optimize.call();
|
this.hooks.optimize.call();
|
||||||
|
@ -1513,11 +1515,11 @@ class Compilation extends Tapable {
|
||||||
addAllToSet(this.contextDependencies, module.buildInfo.contextDependencies);
|
addAllToSet(this.contextDependencies, module.buildInfo.contextDependencies);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.errors.forEach(error => {
|
for(const error of this.errors) {
|
||||||
if(typeof error.missing === "object" && error.missing && error.missing[Symbol.iterator]) {
|
if(typeof error.missing === "object" && error.missing && error.missing[Symbol.iterator]) {
|
||||||
addAllToSet(this.missingDependencies, error.missing);
|
addAllToSet(this.missingDependencies, error.missing);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
this.fileDependencies.sort();
|
this.fileDependencies.sort();
|
||||||
this.contextDependencies.sort();
|
this.contextDependencies.sort();
|
||||||
this.missingDependencies.sort();
|
this.missingDependencies.sort();
|
||||||
|
@ -1533,10 +1535,10 @@ class Compilation extends Tapable {
|
||||||
hash.update(outputOptions.hashSalt);
|
hash.update(outputOptions.hashSalt);
|
||||||
this.mainTemplate.updateHash(hash);
|
this.mainTemplate.updateHash(hash);
|
||||||
this.chunkTemplate.updateHash(hash);
|
this.chunkTemplate.updateHash(hash);
|
||||||
Object.keys(this.moduleTemplates).sort().forEach(key => this.moduleTemplates[key].updateHash(hash));
|
for(const key of Object.keys(this.moduleTemplates).sort()) this.moduleTemplates[key].updateHash(hash);
|
||||||
this.children.forEach(child => hash.update(child.hash));
|
for(const child of this.children) hash.update(child.hash);
|
||||||
this.warnings.forEach(warning => hash.update(`${warning.message}`));
|
for(const warning of this.warnings) hash.update(`${warning.message}`);
|
||||||
this.errors.forEach(error => hash.update(`${error.message}`));
|
for(const error of this.errors) hash.update(`${error.message}`);
|
||||||
const modules = this.modules;
|
const modules = this.modules;
|
||||||
for(let i = 0; i < modules.length; i++) {
|
for(let i = 0; i < modules.length; i++) {
|
||||||
const module = modules[i];
|
const module = modules[i];
|
||||||
|
@ -1595,11 +1597,11 @@ class Compilation extends Tapable {
|
||||||
for(let i = 0; i < this.modules.length; i++) {
|
for(let i = 0; i < this.modules.length; i++) {
|
||||||
const module = this.modules[i];
|
const module = this.modules[i];
|
||||||
if(module.buildInfo.assets) {
|
if(module.buildInfo.assets) {
|
||||||
Object.keys(module.buildInfo.assets).forEach((assetName) => {
|
for(const assetName of Object.keys(module.buildInfo.assets)) {
|
||||||
const fileName = this.getPath(assetName);
|
const fileName = this.getPath(assetName);
|
||||||
this.assets[fileName] = module.buildInfo.assets[assetName];
|
this.assets[fileName] = module.buildInfo.assets[assetName];
|
||||||
this.hooks.moduleAsset.call(module, fileName);
|
this.hooks.moduleAsset.call(module, fileName);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
*/
|
*/
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
const asyncLib = require("async");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const util = require("util");
|
const util = require("util");
|
||||||
const Tapable = require("tapable").Tapable;
|
const Tapable = require("tapable").Tapable;
|
||||||
|
@ -224,9 +225,9 @@ class Compiler extends Tapable {
|
||||||
if(err) return callback(err);
|
if(err) return callback(err);
|
||||||
|
|
||||||
this.parentCompilation.children.push(compilation);
|
this.parentCompilation.children.push(compilation);
|
||||||
Object.keys(compilation.assets).forEach(name => {
|
for(const name of Object.keys(compilation.assets)) {
|
||||||
this.parentCompilation.assets[name] = compilation.assets[name];
|
this.parentCompilation.assets[name] = compilation.assets[name];
|
||||||
});
|
}
|
||||||
|
|
||||||
const entries = Array.from(compilation.entrypoints.values(), ep => ep.chunks).reduce((array, chunks) => {
|
const entries = Array.from(compilation.entrypoints.values(), ep => ep.chunks).reduce((array, chunks) => {
|
||||||
return array.concat(chunks);
|
return array.concat(chunks);
|
||||||
|
@ -247,7 +248,7 @@ class Compiler extends Tapable {
|
||||||
const emitFiles = (err) => {
|
const emitFiles = (err) => {
|
||||||
if(err) return callback(err);
|
if(err) return callback(err);
|
||||||
|
|
||||||
require("async").forEach(Object.keys(compilation.assets), (file, callback) => {
|
asyncLib.forEach(Object.keys(compilation.assets), (file, callback) => {
|
||||||
|
|
||||||
let targetFile = file;
|
let targetFile = file;
|
||||||
const queryStringIdx = targetFile.indexOf("?");
|
const queryStringIdx = targetFile.indexOf("?");
|
||||||
|
@ -345,7 +346,7 @@ class Compiler extends Tapable {
|
||||||
createChildCompiler(compilation, compilerName, compilerIndex, outputOptions, plugins) {
|
createChildCompiler(compilation, compilerName, compilerIndex, outputOptions, plugins) {
|
||||||
const childCompiler = new Compiler(this.context);
|
const childCompiler = new Compiler(this.context);
|
||||||
if(Array.isArray(plugins)) {
|
if(Array.isArray(plugins)) {
|
||||||
plugins.forEach(plugin => plugin.apply(childCompiler));
|
for(const plugin of plugins) plugin.apply(childCompiler);
|
||||||
}
|
}
|
||||||
for(const name in this.hooks) {
|
for(const name in this.hooks) {
|
||||||
if(!["make", "compile", "emit", "afterEmit", "invalid", "done", "thisCompilation"].includes(name)) {
|
if(!["make", "compile", "emit", "afterEmit", "invalid", "done", "thisCompilation"].includes(name)) {
|
||||||
|
|
|
@ -155,10 +155,10 @@ class ContextModule extends Module {
|
||||||
}
|
}
|
||||||
|
|
||||||
// enhance dependencies with meta info
|
// enhance dependencies with meta info
|
||||||
dependencies.forEach(dep => {
|
for(const dep of dependencies) {
|
||||||
dep.loc = dep.userRequest;
|
dep.loc = dep.userRequest;
|
||||||
dep.request = this.options.addon + dep.request;
|
dep.request = this.options.addon + dep.request;
|
||||||
});
|
}
|
||||||
|
|
||||||
if(this.options.mode === "sync" || this.options.mode === "eager") {
|
if(this.options.mode === "sync" || this.options.mode === "eager") {
|
||||||
|
|
||||||
|
@ -172,33 +172,36 @@ class ContextModule extends Module {
|
||||||
// and add that block to this context
|
// and add that block to this context
|
||||||
if(dependencies.length > 0) {
|
if(dependencies.length > 0) {
|
||||||
const block = new AsyncDependenciesBlock(this.options.chunkName, this);
|
const block = new AsyncDependenciesBlock(this.options.chunkName, this);
|
||||||
dependencies.forEach(dep => {
|
for(const dep of dependencies) {
|
||||||
block.addDependency(dep);
|
block.addDependency(dep);
|
||||||
});
|
}
|
||||||
this.addBlock(block);
|
this.addBlock(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if(this.options.mode === "weak" || this.options.mode === "async-weak") {
|
} else if(this.options.mode === "weak" || this.options.mode === "async-weak") {
|
||||||
|
|
||||||
// we mark all dependencies as weak
|
// we mark all dependencies as weak
|
||||||
dependencies.forEach(dep => dep.weak = true);
|
for(const dep of dependencies) {
|
||||||
|
dep.weak = true;
|
||||||
|
}
|
||||||
this.dependencies = dependencies;
|
this.dependencies = dependencies;
|
||||||
|
|
||||||
} else if(this.options.mode === "lazy") {
|
} else if(this.options.mode === "lazy") {
|
||||||
// if we are lazy create a new async dependency block per dependency
|
// if we are lazy create a new async dependency block per dependency
|
||||||
// and add all blocks to this context
|
// and add all blocks to this context
|
||||||
dependencies.forEach((dep, idx) => {
|
let index = 0;
|
||||||
|
for(const dep of dependencies) {
|
||||||
let chunkName = this.options.chunkName;
|
let chunkName = this.options.chunkName;
|
||||||
if(chunkName) {
|
if(chunkName) {
|
||||||
if(!/\[(index|request)\]/.test(chunkName))
|
if(!/\[(index|request)\]/.test(chunkName))
|
||||||
chunkName += "[index]";
|
chunkName += "[index]";
|
||||||
chunkName = chunkName.replace(/\[index\]/g, idx);
|
chunkName = chunkName.replace(/\[index\]/g, index++);
|
||||||
chunkName = chunkName.replace(/\[request\]/g, Template.toPath(dep.userRequest));
|
chunkName = chunkName.replace(/\[request\]/g, Template.toPath(dep.userRequest));
|
||||||
}
|
}
|
||||||
const block = new AsyncDependenciesBlock(chunkName, dep.module, dep.loc, dep.userRequest);
|
const block = new AsyncDependenciesBlock(chunkName, dep.module, dep.loc, dep.userRequest);
|
||||||
block.addDependency(dep);
|
block.addDependency(dep);
|
||||||
this.addBlock(block);
|
this.addBlock(block);
|
||||||
});
|
}
|
||||||
} else {
|
} else {
|
||||||
callback(new Error(`Unsupported mode "${this.options.mode}" in context`));
|
callback(new Error(`Unsupported mode "${this.options.mode}" in context`));
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -58,10 +58,10 @@ class ContextReplacementPlugin {
|
||||||
if(typeof newContentCallback === "function") {
|
if(typeof newContentCallback === "function") {
|
||||||
newContentCallback(result);
|
newContentCallback(result);
|
||||||
} else {
|
} else {
|
||||||
result.dependencies.forEach((d) => {
|
for(const d of result.dependencies) {
|
||||||
if(d.critical)
|
if(d.critical)
|
||||||
d.critical = false;
|
d.critical = false;
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -84,10 +84,10 @@ class ContextReplacementPlugin {
|
||||||
result.resource = path.resolve(origResource, result.resource);
|
result.resource = path.resolve(origResource, result.resource);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result.dependencies.forEach((d) => {
|
for(const d of result.dependencies) {
|
||||||
if(d.critical)
|
if(d.critical)
|
||||||
d.critical = false;
|
d.critical = false;
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -17,25 +17,25 @@ class DependenciesBlockVariable {
|
||||||
updateHash(hash) {
|
updateHash(hash) {
|
||||||
hash.update(this.name);
|
hash.update(this.name);
|
||||||
hash.update(this.expression);
|
hash.update(this.expression);
|
||||||
this.dependencies.forEach(d => {
|
for(const d of this.dependencies) {
|
||||||
d.updateHash(hash);
|
d.updateHash(hash);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
expressionSource(dependencyTemplates, runtimeTemplate) {
|
expressionSource(dependencyTemplates, runtimeTemplate) {
|
||||||
const source = new ReplaceSource(new RawSource(this.expression));
|
const source = new ReplaceSource(new RawSource(this.expression));
|
||||||
this.dependencies.forEach(dep => {
|
for(const dep of this.dependencies) {
|
||||||
const template = dependencyTemplates.get(dep.constructor);
|
const template = dependencyTemplates.get(dep.constructor);
|
||||||
if(!template) throw new Error(`No template for dependency: ${dep.constructor.name}`);
|
if(!template) throw new Error(`No template for dependency: ${dep.constructor.name}`);
|
||||||
template.apply(dep, source, runtimeTemplate, dependencyTemplates);
|
template.apply(dep, source, runtimeTemplate, dependencyTemplates);
|
||||||
});
|
}
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
disconnect() {
|
disconnect() {
|
||||||
this.dependencies.forEach(d => {
|
for(const d of this.dependencies) {
|
||||||
d.disconnect();
|
d.disconnect();
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hasDependencies(filter) {
|
hasDependencies(filter) {
|
||||||
|
|
|
@ -21,7 +21,9 @@ module.exports = class EntryOptionPlugin {
|
||||||
if(typeof entry === "string" || Array.isArray(entry)) {
|
if(typeof entry === "string" || Array.isArray(entry)) {
|
||||||
itemToPlugin(context, entry, "main").apply(compiler);
|
itemToPlugin(context, entry, "main").apply(compiler);
|
||||||
} else if(typeof entry === "object") {
|
} else if(typeof entry === "object") {
|
||||||
Object.keys(entry).forEach(name => itemToPlugin(context, entry[name], name).apply(compiler));
|
for(const name of Object.keys(entry)) {
|
||||||
|
itemToPlugin(context, entry[name], name).apply(compiler);
|
||||||
|
}
|
||||||
} else if(typeof entry === "function") {
|
} else if(typeof entry === "function") {
|
||||||
new DynamicEntryPlugin(context, entry).apply(compiler);
|
new DynamicEntryPlugin(context, entry).apply(compiler);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,10 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const addToSet = (a, b) => {
|
const addToSet = (a, b) => {
|
||||||
b.forEach(item => {
|
for(const item of b) {
|
||||||
if(!a.includes(item))
|
if(!a.includes(item))
|
||||||
a.push(item);
|
a.push(item);
|
||||||
});
|
}
|
||||||
return a;
|
return a;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -50,9 +50,17 @@ class FlagDependencyUsagePlugin {
|
||||||
};
|
};
|
||||||
|
|
||||||
const processDependenciesBlock = (depBlock, usedExports) => {
|
const processDependenciesBlock = (depBlock, usedExports) => {
|
||||||
depBlock.dependencies.forEach(dep => processDependency(dep));
|
for(const dep of depBlock.dependencies) {
|
||||||
depBlock.variables.forEach(variable => variable.dependencies.forEach(dep => processDependency(dep)));
|
processDependency(dep);
|
||||||
depBlock.blocks.forEach(block => queue.push([block, usedExports]));
|
}
|
||||||
|
for(const variable of depBlock.variables) {
|
||||||
|
for(const dep of variable.dependencies) {
|
||||||
|
processDependency(dep);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(const block of depBlock.blocks) {
|
||||||
|
queue.push([block, usedExports]);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const processDependency = dep => {
|
const processDependency = dep => {
|
||||||
|
@ -67,14 +75,16 @@ class FlagDependencyUsagePlugin {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
modules.forEach(module => module.used = false);
|
for(const module of modules) {
|
||||||
|
module.used = false;
|
||||||
|
}
|
||||||
|
|
||||||
const queue = [];
|
const queue = [];
|
||||||
compilation.chunks.forEach(chunk => {
|
for(const chunk of compilation.chunks) {
|
||||||
if(chunk.entryModule) {
|
if(chunk.entryModule) {
|
||||||
processModule(chunk.entryModule, true);
|
processModule(chunk.entryModule, true);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
while(queue.length) {
|
while(queue.length) {
|
||||||
const queueItem = queue.pop();
|
const queueItem = queue.pop();
|
||||||
|
|
|
@ -12,7 +12,7 @@ class FlagInitialModulesAsUsedPlugin {
|
||||||
apply(compiler) {
|
apply(compiler) {
|
||||||
compiler.hooks.compilation.tap("FlagInitialModulesAsUsedPlugin", (compilation) => {
|
compiler.hooks.compilation.tap("FlagInitialModulesAsUsedPlugin", (compilation) => {
|
||||||
compilation.hooks.afterOptimizeChunks.tap("FlagInitialModulesAsUsedPlugin", (chunks) => {
|
compilation.hooks.afterOptimizeChunks.tap("FlagInitialModulesAsUsedPlugin", (chunks) => {
|
||||||
chunks.forEach((chunk) => {
|
for(const chunk of chunks) {
|
||||||
if(!chunk.isOnlyInitial()) {
|
if(!chunk.isOnlyInitial()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ class FlagInitialModulesAsUsedPlugin {
|
||||||
module.usedExports = true;
|
module.usedExports = true;
|
||||||
module.addReason(null, null, this.explanation);
|
module.addReason(null, null, this.explanation);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,10 +50,15 @@ class FunctionModuleTemplatePlugin {
|
||||||
else if(module.usedExports)
|
else if(module.usedExports)
|
||||||
source.add(Template.toComment("all exports used") + "\n");
|
source.add(Template.toComment("all exports used") + "\n");
|
||||||
if(module.optimizationBailout) {
|
if(module.optimizationBailout) {
|
||||||
module.optimizationBailout.forEach(text => {
|
for(const text of module.optimizationBailout) {
|
||||||
if(typeof text === "function") text = text(moduleTemplate.runtimeTemplate.requestShortener);
|
let code;
|
||||||
source.add(Template.toComment(`${text}`) + "\n");
|
if(typeof text === "function") {
|
||||||
});
|
code = text(moduleTemplate.runtimeTemplate.requestShortener);
|
||||||
|
} else {
|
||||||
|
code = text;
|
||||||
|
}
|
||||||
|
source.add(Template.toComment(`${code}`) + "\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
source.add(moduleSource);
|
source.add(moduleSource);
|
||||||
return source;
|
return source;
|
||||||
|
|
|
@ -13,6 +13,7 @@ class HashedModuleIdsPlugin {
|
||||||
validateOptions(schema, options || {}, "Hashed Module Ids Plugin");
|
validateOptions(schema, options || {}, "Hashed Module Ids Plugin");
|
||||||
|
|
||||||
this.options = Object.assign({
|
this.options = Object.assign({
|
||||||
|
context: null,
|
||||||
hashFunction: "md5",
|
hashFunction: "md5",
|
||||||
hashDigest: "base64",
|
hashDigest: "base64",
|
||||||
hashDigestLength: 4
|
hashDigestLength: 4
|
||||||
|
@ -24,7 +25,7 @@ class HashedModuleIdsPlugin {
|
||||||
compiler.hooks.compilation.tap("HashedModuleIdsPlugin", (compilation) => {
|
compiler.hooks.compilation.tap("HashedModuleIdsPlugin", (compilation) => {
|
||||||
const usedIds = new Set();
|
const usedIds = new Set();
|
||||||
compilation.hooks.beforeModuleIds.tap("HashedModuleIdsPlugin", (modules) => {
|
compilation.hooks.beforeModuleIds.tap("HashedModuleIdsPlugin", (modules) => {
|
||||||
modules.forEach((module) => {
|
for(const module of modules) {
|
||||||
if(module.id === null && module.libIdent) {
|
if(module.id === null && module.libIdent) {
|
||||||
const id = module.libIdent({
|
const id = module.libIdent({
|
||||||
context: this.options.context || compiler.options.context
|
context: this.options.context || compiler.options.context
|
||||||
|
@ -38,7 +39,7 @@ class HashedModuleIdsPlugin {
|
||||||
module.id = hashId.substr(0, len);
|
module.id = hashId.substr(0, len);
|
||||||
usedIds.add(module.id);
|
usedIds.add(module.id);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,20 +51,20 @@ module.exports = class HotModuleReplacementPlugin {
|
||||||
if(records.hash === compilation.hash) return;
|
if(records.hash === compilation.hash) return;
|
||||||
records.hash = compilation.hash;
|
records.hash = compilation.hash;
|
||||||
records.moduleHashs = {};
|
records.moduleHashs = {};
|
||||||
compilation.modules.forEach(module => {
|
for(const module of compilation.modules) {
|
||||||
const identifier = module.identifier();
|
const identifier = module.identifier();
|
||||||
const hash = createHash(compilation.outputOptions.hashFunction);
|
const hash = createHash(compilation.outputOptions.hashFunction);
|
||||||
module.updateHash(hash);
|
module.updateHash(hash);
|
||||||
records.moduleHashs[identifier] = hash.digest("hex");
|
records.moduleHashs[identifier] = hash.digest("hex");
|
||||||
});
|
}
|
||||||
records.chunkHashs = {};
|
records.chunkHashs = {};
|
||||||
compilation.chunks.forEach(chunk => {
|
for(const chunk of compilation.chunks) {
|
||||||
records.chunkHashs[chunk.id] = chunk.hash;
|
records.chunkHashs[chunk.id] = chunk.hash;
|
||||||
});
|
}
|
||||||
records.chunkModuleIds = {};
|
records.chunkModuleIds = {};
|
||||||
compilation.chunks.forEach(chunk => {
|
for(const chunk of compilation.chunks) {
|
||||||
records.chunkModuleIds[chunk.id] = Array.from(chunk.modulesIterable, m => m.id);
|
records.chunkModuleIds[chunk.id] = Array.from(chunk.modulesIterable, m => m.id);
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
let initialPass = false;
|
let initialPass = false;
|
||||||
let recompilation = false;
|
let recompilation = false;
|
||||||
|
@ -99,18 +99,18 @@ module.exports = class HotModuleReplacementPlugin {
|
||||||
const records = compilation.records;
|
const records = compilation.records;
|
||||||
if(records.hash === compilation.hash) return;
|
if(records.hash === compilation.hash) return;
|
||||||
if(!records.moduleHashs || !records.chunkHashs || !records.chunkModuleIds) return;
|
if(!records.moduleHashs || !records.chunkHashs || !records.chunkModuleIds) return;
|
||||||
compilation.modules.forEach(module => {
|
for(const module of compilation.modules) {
|
||||||
const identifier = module.identifier();
|
const identifier = module.identifier();
|
||||||
let hash = createHash(compilation.outputOptions.hashFunction);
|
let hash = createHash(compilation.outputOptions.hashFunction);
|
||||||
module.updateHash(hash);
|
module.updateHash(hash);
|
||||||
hash = hash.digest("hex");
|
hash = hash.digest("hex");
|
||||||
module.hotUpdate = records.moduleHashs[identifier] !== hash;
|
module.hotUpdate = records.moduleHashs[identifier] !== hash;
|
||||||
});
|
}
|
||||||
const hotUpdateMainContent = {
|
const hotUpdateMainContent = {
|
||||||
h: compilation.hash,
|
h: compilation.hash,
|
||||||
c: {},
|
c: {},
|
||||||
};
|
};
|
||||||
Object.keys(records.chunkHashs).forEach(chunkId => {
|
for(let chunkId of Object.keys(records.chunkHashs)) {
|
||||||
chunkId = isNaN(+chunkId) ? chunkId : +chunkId;
|
chunkId = isNaN(+chunkId) ? chunkId : +chunkId;
|
||||||
const currentChunk = compilation.chunks.find(chunk => chunk.id === chunkId);
|
const currentChunk = compilation.chunks.find(chunk => chunk.id === chunkId);
|
||||||
if(currentChunk) {
|
if(currentChunk) {
|
||||||
|
@ -135,7 +135,7 @@ module.exports = class HotModuleReplacementPlugin {
|
||||||
} else {
|
} else {
|
||||||
hotUpdateMainContent.c[chunkId] = false;
|
hotUpdateMainContent.c[chunkId] = false;
|
||||||
}
|
}
|
||||||
}, compilation);
|
}
|
||||||
const source = new RawSource(JSON.stringify(hotUpdateMainContent));
|
const source = new RawSource(JSON.stringify(hotUpdateMainContent));
|
||||||
const filename = compilation.getPath(hotUpdateMainFilename, {
|
const filename = compilation.getPath(hotUpdateMainFilename, {
|
||||||
hash: records.hash
|
hash: records.hash
|
||||||
|
|
|
@ -28,10 +28,12 @@ class LoaderOptionsPlugin {
|
||||||
if(!resource) return;
|
if(!resource) return;
|
||||||
const i = resource.indexOf("?");
|
const i = resource.indexOf("?");
|
||||||
if(ModuleFilenameHelpers.matchObject(options, i < 0 ? resource : resource.substr(0, i))) {
|
if(ModuleFilenameHelpers.matchObject(options, i < 0 ? resource : resource.substr(0, i))) {
|
||||||
const filterSet = new Set(["include", "exclude", "test"]);
|
for(const key of Object.keys(options)) {
|
||||||
Object.keys(options)
|
if(key === "include" || key === "exclude" || key === "test") {
|
||||||
.filter((key) => !filterSet.has(key))
|
continue;
|
||||||
.forEach((key) => context[key] = options[key]);
|
}
|
||||||
|
context[key] = options[key];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -30,25 +30,27 @@ module.exports = class MultiCompiler extends Tapable {
|
||||||
this.compilers = compilers;
|
this.compilers = compilers;
|
||||||
let doneCompilers = 0;
|
let doneCompilers = 0;
|
||||||
let compilerStats = [];
|
let compilerStats = [];
|
||||||
this.compilers.forEach((compiler, idx) => {
|
let index = 0;
|
||||||
|
for(const compiler of this.compilers) {
|
||||||
let compilerDone = false;
|
let compilerDone = false;
|
||||||
compiler.hooks.done.tap("MultiCompiler", stats => {
|
const compilerIndex = index++;
|
||||||
|
compiler.hooks.done.tap("MultiCompiler", stats => { // eslint-disable-line no-loop-func
|
||||||
if(!compilerDone) {
|
if(!compilerDone) {
|
||||||
compilerDone = true;
|
compilerDone = true;
|
||||||
doneCompilers++;
|
doneCompilers++;
|
||||||
}
|
}
|
||||||
compilerStats[idx] = stats;
|
compilerStats[compilerIndex] = stats;
|
||||||
if(doneCompilers === this.compilers.length) {
|
if(doneCompilers === this.compilers.length) {
|
||||||
this.hooks.done.call(new MultiStats(compilerStats));
|
this.hooks.done.call(new MultiStats(compilerStats));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
compiler.hooks.invalid.tap("MultiCompiler", () => {
|
compiler.hooks.invalid.tap("MultiCompiler", () => { // eslint-disable-line no-loop-func
|
||||||
if(compilerDone) {
|
if(compilerDone) {
|
||||||
compilerDone = false;
|
compilerDone = false;
|
||||||
doneCompilers--;
|
doneCompilers--;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get outputPath() {
|
get outputPath() {
|
||||||
|
@ -72,15 +74,15 @@ module.exports = class MultiCompiler extends Tapable {
|
||||||
}
|
}
|
||||||
|
|
||||||
set inputFileSystem(value) {
|
set inputFileSystem(value) {
|
||||||
this.compilers.forEach(compiler => {
|
for(const compiler of this.compilers) {
|
||||||
compiler.inputFileSystem = value;
|
compiler.inputFileSystem = value;
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
set outputFileSystem(value) {
|
set outputFileSystem(value) {
|
||||||
this.compilers.forEach(compiler => {
|
for(const compiler of this.compilers) {
|
||||||
compiler.outputFileSystem = value;
|
compiler.outputFileSystem = value;
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
validateDependencies(callback) {
|
validateDependencies(callback) {
|
||||||
|
@ -225,9 +227,9 @@ module.exports = class MultiCompiler extends Tapable {
|
||||||
}
|
}
|
||||||
|
|
||||||
purgeInputFileSystem() {
|
purgeInputFileSystem() {
|
||||||
this.compilers.forEach((compiler) => {
|
for(const compiler of this.compilers) {
|
||||||
if(compiler.inputFileSystem && compiler.inputFileSystem.purge)
|
if(compiler.inputFileSystem && compiler.inputFileSystem.purge)
|
||||||
compiler.inputFileSystem.purge();
|
compiler.inputFileSystem.purge();
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -50,7 +50,8 @@ class MultiModule extends Module {
|
||||||
|
|
||||||
source(dependencyTemplates, runtimeTemplate) {
|
source(dependencyTemplates, runtimeTemplate) {
|
||||||
const str = [];
|
const str = [];
|
||||||
this.dependencies.forEach((dep, idx) => {
|
let idx = 0;
|
||||||
|
for(const dep of this.dependencies) {
|
||||||
if(dep.module) {
|
if(dep.module) {
|
||||||
if(idx === this.dependencies.length - 1)
|
if(idx === this.dependencies.length - 1)
|
||||||
str.push("module.exports = ");
|
str.push("module.exports = ");
|
||||||
|
@ -64,7 +65,8 @@ class MultiModule extends Module {
|
||||||
str.push(content);
|
str.push(content);
|
||||||
}
|
}
|
||||||
str.push(";\n");
|
str.push(";\n");
|
||||||
});
|
idx++;
|
||||||
|
}
|
||||||
return new RawSource(str.join(""));
|
return new RawSource(str.join(""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,10 +36,11 @@ class MultiStats {
|
||||||
});
|
});
|
||||||
const showVersion = typeof options.version === "undefined" ? jsons.every(j => j.version) : options.version !== false;
|
const showVersion = typeof options.version === "undefined" ? jsons.every(j => j.version) : options.version !== false;
|
||||||
const showHash = typeof options.hash === "undefined" ? jsons.every(j => j.hash) : options.hash !== false;
|
const showHash = typeof options.hash === "undefined" ? jsons.every(j => j.hash) : options.hash !== false;
|
||||||
jsons.forEach(j => {
|
if(showVersion) {
|
||||||
if(showVersion)
|
for(const j of jsons) {
|
||||||
delete j.version;
|
delete j.version;
|
||||||
});
|
}
|
||||||
|
}
|
||||||
const obj = {
|
const obj = {
|
||||||
errors: jsons.reduce((arr, j) => {
|
errors: jsons.reduce((arr, j) => {
|
||||||
return arr.concat(j.errors.map(msg => {
|
return arr.concat(j.errors.map(msg => {
|
||||||
|
|
|
@ -13,19 +13,20 @@ class MultiWatching {
|
||||||
}
|
}
|
||||||
|
|
||||||
invalidate() {
|
invalidate() {
|
||||||
this.watchings.forEach((watching) => watching.invalidate());
|
for(const watching of this.watchings) {
|
||||||
|
watching.invalidate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
close(callback) {
|
close(callback) {
|
||||||
if(callback === undefined) callback = () => { /*do nothing*/ };
|
|
||||||
|
|
||||||
asyncLib.forEach(this.watchings, (watching, finishedCallback) => {
|
asyncLib.forEach(this.watchings, (watching, finishedCallback) => {
|
||||||
watching.close(finishedCallback);
|
watching.close(finishedCallback);
|
||||||
}, err => {
|
}, err => {
|
||||||
this.compiler.hooks.watchClose.call();
|
this.compiler.hooks.watchClose.call();
|
||||||
callback(err);
|
if(typeof callback === "function") {
|
||||||
|
callback(err);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,11 +17,11 @@ class NamedChunksPlugin {
|
||||||
apply(compiler) {
|
apply(compiler) {
|
||||||
compiler.hooks.compilation.tap("NamedChunksPlugin", (compilation) => {
|
compiler.hooks.compilation.tap("NamedChunksPlugin", (compilation) => {
|
||||||
compilation.hooks.beforeChunkIds.tap("NamedChunksPlugin", (chunks) => {
|
compilation.hooks.beforeChunkIds.tap("NamedChunksPlugin", (chunks) => {
|
||||||
chunks.forEach((chunk) => {
|
for(const chunk of chunks) {
|
||||||
if(chunk.id === null) {
|
if(chunk.id === null) {
|
||||||
chunk.id = this.nameResolver(chunk);
|
chunk.id = this.nameResolver(chunk);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,13 +12,13 @@ class NamedModulesPlugin {
|
||||||
apply(compiler) {
|
apply(compiler) {
|
||||||
compiler.hooks.compilation.tap("NamedModulesPlugin", (compilation) => {
|
compiler.hooks.compilation.tap("NamedModulesPlugin", (compilation) => {
|
||||||
compilation.hooks.beforeModuleIds.tap("NamedModulesPlugin", (modules) => {
|
compilation.hooks.beforeModuleIds.tap("NamedModulesPlugin", (modules) => {
|
||||||
modules.forEach((module) => {
|
for(const module of modules) {
|
||||||
if(module.id === null && module.libIdent) {
|
if(module.id === null && module.libIdent) {
|
||||||
module.id = module.libIdent({
|
module.id = module.libIdent({
|
||||||
context: this.options.context || compiler.options.context
|
context: this.options.context || compiler.options.context
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -422,8 +422,9 @@ class NormalModule extends Module {
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceBlock(block, availableVars, dependencyTemplates, source, runtimeTemplate) {
|
sourceBlock(block, availableVars, dependencyTemplates, source, runtimeTemplate) {
|
||||||
block.dependencies.forEach((dependency) => this.sourceDependency(
|
for(const dependency of block.dependencies) {
|
||||||
dependency, dependencyTemplates, source, runtimeTemplate));
|
this.sourceDependency(dependency, dependencyTemplates, source, runtimeTemplate);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the variables of all blocks that we need to inject.
|
* Get the variables of all blocks that we need to inject.
|
||||||
|
@ -493,15 +494,15 @@ class NormalModule extends Module {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
block.blocks.forEach((block) =>
|
for(const childBlock of block.blocks) {
|
||||||
this.sourceBlock(
|
this.sourceBlock(
|
||||||
block,
|
childBlock,
|
||||||
availableVars.concat(vars),
|
availableVars.concat(vars),
|
||||||
dependencyTemplates,
|
dependencyTemplates,
|
||||||
source,
|
source,
|
||||||
runtimeTemplate
|
runtimeTemplate
|
||||||
)
|
);
|
||||||
);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
source(dependencyTemplates, runtimeTemplate) {
|
source(dependencyTemplates, runtimeTemplate) {
|
||||||
|
|
|
@ -176,13 +176,13 @@ class NormalModuleFactory extends Tapable {
|
||||||
|
|
||||||
// translate option idents
|
// translate option idents
|
||||||
try {
|
try {
|
||||||
loaders.forEach(item => {
|
for(const item of loaders) {
|
||||||
if(typeof item.options === "string" && item.options[0] === "?") {
|
if(typeof item.options === "string" && item.options[0] === "?") {
|
||||||
const ident = item.options.substr(1);
|
const ident = item.options.substr(1);
|
||||||
item.options = this.ruleSet.findOptionsByIdent(ident);
|
item.options = this.ruleSet.findOptionsByIdent(ident);
|
||||||
item.ident = ident;
|
item.ident = ident;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
return callback(e);
|
return callback(e);
|
||||||
}
|
}
|
||||||
|
@ -218,7 +218,7 @@ class NormalModuleFactory extends Tapable {
|
||||||
const useLoadersPost = [];
|
const useLoadersPost = [];
|
||||||
const useLoaders = [];
|
const useLoaders = [];
|
||||||
const useLoadersPre = [];
|
const useLoadersPre = [];
|
||||||
result.forEach(r => {
|
for(const r of result) {
|
||||||
if(r.type === "use") {
|
if(r.type === "use") {
|
||||||
if(r.enforce === "post" && !noPrePostAutoLoaders)
|
if(r.enforce === "post" && !noPrePostAutoLoaders)
|
||||||
useLoadersPost.push(r.value);
|
useLoadersPost.push(r.value);
|
||||||
|
@ -231,7 +231,7 @@ class NormalModuleFactory extends Tapable {
|
||||||
} else {
|
} else {
|
||||||
settings[r.type] = r.value;
|
settings[r.type] = r.value;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
asyncLib.parallel([
|
asyncLib.parallel([
|
||||||
this.resolveRequestArray.bind(this, contextInfo, this.context, useLoadersPost, loaderResolver),
|
this.resolveRequestArray.bind(this, contextInfo, this.context, useLoadersPost, loaderResolver),
|
||||||
this.resolveRequestArray.bind(this, contextInfo, this.context, useLoaders, loaderResolver),
|
this.resolveRequestArray.bind(this, contextInfo, this.context, useLoaders, loaderResolver),
|
||||||
|
@ -291,7 +291,9 @@ class NormalModuleFactory extends Tapable {
|
||||||
if(err) return callback(err);
|
if(err) return callback(err);
|
||||||
|
|
||||||
if(module && this.cachePredicate(module)) {
|
if(module && this.cachePredicate(module)) {
|
||||||
dependencies.forEach(d => d.__NormalModuleFactoryCache = module);
|
for(const d of dependencies) {
|
||||||
|
d.__NormalModuleFactoryCache = module;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(null, module);
|
callback(null, module);
|
||||||
|
|
|
@ -22,13 +22,13 @@ const createDefaultHandler = profile => {
|
||||||
if(percentage < 10) {
|
if(percentage < 10) {
|
||||||
msg = ` ${msg}`;
|
msg = ` ${msg}`;
|
||||||
}
|
}
|
||||||
details.forEach(detail => {
|
for(let detail of details) {
|
||||||
if(!detail) return;
|
if(!detail) continue;
|
||||||
if(detail.length > 40) {
|
if(detail.length > 40) {
|
||||||
detail = `...${detail.substr(detail.length - 37)}`;
|
detail = `...${detail.substr(detail.length - 37)}`;
|
||||||
}
|
}
|
||||||
msg += ` ${detail}`;
|
msg += ` ${detail}`;
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
if(profile) {
|
if(profile) {
|
||||||
state = state.replace(/^\d+\/\d+\s+/, "");
|
state = state.replace(/^\d+\/\d+\s+/, "");
|
||||||
|
|
|
@ -18,25 +18,25 @@ class RecordIdsPlugin {
|
||||||
if(!records.modules) records.modules = {};
|
if(!records.modules) records.modules = {};
|
||||||
if(!records.modules.byIdentifier) records.modules.byIdentifier = {};
|
if(!records.modules.byIdentifier) records.modules.byIdentifier = {};
|
||||||
if(!records.modules.usedIds) records.modules.usedIds = {};
|
if(!records.modules.usedIds) records.modules.usedIds = {};
|
||||||
modules.forEach(module => {
|
for(const module of modules) {
|
||||||
const identifier = portableIds ? identifierUtils.makePathsRelative(compiler.context, module.identifier(), compilation.cache) : module.identifier();
|
const identifier = portableIds ? identifierUtils.makePathsRelative(compiler.context, module.identifier(), compilation.cache) : module.identifier();
|
||||||
records.modules.byIdentifier[identifier] = module.id;
|
records.modules.byIdentifier[identifier] = module.id;
|
||||||
records.modules.usedIds[module.id] = module.id;
|
records.modules.usedIds[module.id] = module.id;
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
compilation.hooks.reviveModules.tap("RecordIdsPlugin", (modules, records) => {
|
compilation.hooks.reviveModules.tap("RecordIdsPlugin", (modules, records) => {
|
||||||
if(!records.modules) return;
|
if(!records.modules) return;
|
||||||
if(records.modules.byIdentifier) {
|
if(records.modules.byIdentifier) {
|
||||||
const usedIds = new Set();
|
const usedIds = new Set();
|
||||||
modules.forEach(module => {
|
for(const module of modules) {
|
||||||
if(module.id !== null) return;
|
if(module.id !== null) continue;
|
||||||
const identifier = portableIds ? identifierUtils.makePathsRelative(compiler.context, module.identifier(), compilation.cache) : module.identifier();
|
const identifier = portableIds ? identifierUtils.makePathsRelative(compiler.context, module.identifier(), compilation.cache) : module.identifier();
|
||||||
const id = records.modules.byIdentifier[identifier];
|
const id = records.modules.byIdentifier[identifier];
|
||||||
if(id === undefined) return;
|
if(id === undefined) continue;
|
||||||
if(usedIds.has(id)) return;
|
if(usedIds.has(id)) continue;
|
||||||
usedIds.add(id);
|
usedIds.add(id);
|
||||||
module.id = id;
|
module.id = id;
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
if(Array.isArray(records.modules.usedIds))
|
if(Array.isArray(records.modules.usedIds))
|
||||||
compilation.usedModuleIds = new Set(records.modules.usedIds);
|
compilation.usedModuleIds = new Set(records.modules.usedIds);
|
||||||
|
@ -71,7 +71,7 @@ class RecordIdsPlugin {
|
||||||
if(!records.chunks.byName) records.chunks.byName = {};
|
if(!records.chunks.byName) records.chunks.byName = {};
|
||||||
if(!records.chunks.bySource) records.chunks.bySource = {};
|
if(!records.chunks.bySource) records.chunks.bySource = {};
|
||||||
const usedIds = new Set();
|
const usedIds = new Set();
|
||||||
chunks.forEach(chunk => {
|
for(const chunk of chunks) {
|
||||||
const name = chunk.name;
|
const name = chunk.name;
|
||||||
if(name) records.chunks.byName[name] = chunk.id;
|
if(name) records.chunks.byName[name] = chunk.id;
|
||||||
const sources = getChunkSources(chunk);
|
const sources = getChunkSources(chunk);
|
||||||
|
@ -79,25 +79,25 @@ class RecordIdsPlugin {
|
||||||
records.chunks.bySource[source] = chunk.id;
|
records.chunks.bySource[source] = chunk.id;
|
||||||
}
|
}
|
||||||
usedIds.add(chunk.id);
|
usedIds.add(chunk.id);
|
||||||
});
|
}
|
||||||
records.chunks.usedIds = Array.from(usedIds);
|
records.chunks.usedIds = Array.from(usedIds);
|
||||||
});
|
});
|
||||||
compilation.hooks.reviveChunks.tap("RecordIdsPlugin", (chunks, records) => {
|
compilation.hooks.reviveChunks.tap("RecordIdsPlugin", (chunks, records) => {
|
||||||
if(!records.chunks) return;
|
if(!records.chunks) return;
|
||||||
const usedIds = new Set();
|
const usedIds = new Set();
|
||||||
if(records.chunks.byName) {
|
if(records.chunks.byName) {
|
||||||
chunks.forEach(chunk => {
|
for(const chunk of chunks) {
|
||||||
if(chunk.id !== null) return;
|
if(chunk.id !== null) continue;
|
||||||
if(!chunk.name) return;
|
if(!chunk.name) continue;
|
||||||
const id = records.chunks.byName[chunk.name];
|
const id = records.chunks.byName[chunk.name];
|
||||||
if(id === undefined) return;
|
if(id === undefined) continue;
|
||||||
if(usedIds.has(id)) return;
|
if(usedIds.has(id)) continue;
|
||||||
usedIds.add(id);
|
usedIds.add(id);
|
||||||
chunk.id = id;
|
chunk.id = id;
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
if(records.chunks.bySource) {
|
if(records.chunks.bySource) {
|
||||||
chunks.forEach(chunk => {
|
for(const chunk of chunks) {
|
||||||
const sources = getChunkSources(chunk);
|
const sources = getChunkSources(chunk);
|
||||||
for(const source of sources) {
|
for(const source of sources) {
|
||||||
const id = records.chunks.bySource[source];
|
const id = records.chunks.bySource[source];
|
||||||
|
@ -107,7 +107,7 @@ class RecordIdsPlugin {
|
||||||
chunk.id = id;
|
chunk.id = id;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
if(Array.isArray(records.chunks.usedIds))
|
if(Array.isArray(records.chunks.usedIds))
|
||||||
compilation.usedChunkIds = new Set(records.chunks.usedIds);
|
compilation.usedChunkIds = new Set(records.chunks.usedIds);
|
||||||
|
|
|
@ -231,16 +231,16 @@ module.exports = class RuleSet {
|
||||||
const keys = Object.keys(rule).filter((key) => {
|
const keys = Object.keys(rule).filter((key) => {
|
||||||
return !["resource", "resourceQuery", "compiler", "test", "include", "exclude", "issuer", "loader", "options", "query", "loaders", "use", "rules", "oneOf"].includes(key);
|
return !["resource", "resourceQuery", "compiler", "test", "include", "exclude", "issuer", "loader", "options", "query", "loaders", "use", "rules", "oneOf"].includes(key);
|
||||||
});
|
});
|
||||||
keys.forEach((key) => {
|
for(const key of keys) {
|
||||||
newRule[key] = rule[key];
|
newRule[key] = rule[key];
|
||||||
});
|
}
|
||||||
|
|
||||||
if(Array.isArray(newRule.use)) {
|
if(Array.isArray(newRule.use)) {
|
||||||
newRule.use.forEach((item) => {
|
for(const item of newRule.use) {
|
||||||
if(item.ident) {
|
if(item.ident) {
|
||||||
refs[item.ident] = item.options;
|
refs[item.ident] = item.options;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return newRule;
|
return newRule;
|
||||||
|
@ -304,9 +304,9 @@ module.exports = class RuleSet {
|
||||||
return !["options", "query"].includes(key);
|
return !["options", "query"].includes(key);
|
||||||
});
|
});
|
||||||
|
|
||||||
keys.forEach(function(key) {
|
for(const key of keys) {
|
||||||
newItem[key] = item[key];
|
newItem[key] = item[key];
|
||||||
});
|
}
|
||||||
|
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
|
@ -395,12 +395,12 @@ module.exports = class RuleSet {
|
||||||
const keys = Object.keys(rule).filter((key) => {
|
const keys = Object.keys(rule).filter((key) => {
|
||||||
return !["resource", "resourceQuery", "compiler", "issuer", "rules", "oneOf", "use", "enforce"].includes(key);
|
return !["resource", "resourceQuery", "compiler", "issuer", "rules", "oneOf", "use", "enforce"].includes(key);
|
||||||
});
|
});
|
||||||
keys.forEach((key) => {
|
for(const key of keys) {
|
||||||
result.push({
|
result.push({
|
||||||
type: key,
|
type: key,
|
||||||
value: rule[key]
|
value: rule[key]
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
if(rule.use) {
|
if(rule.use) {
|
||||||
const process = use => {
|
const process = use => {
|
||||||
|
|
|
@ -90,16 +90,16 @@ class SourceMapDevToolPlugin {
|
||||||
const reportProgress = (context && context.reportProgress) ? context.reportProgress : () => {};
|
const reportProgress = (context && context.reportProgress) ? context.reportProgress : () => {};
|
||||||
|
|
||||||
const files = [];
|
const files = [];
|
||||||
chunks.forEach(chunk => {
|
for(const chunk of chunks) {
|
||||||
chunk.files.forEach(file => {
|
for(const file of chunk.files) {
|
||||||
if(matchObject(file)) {
|
if(matchObject(file)) {
|
||||||
files.push({
|
files.push({
|
||||||
file,
|
file,
|
||||||
chunk
|
chunk
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
reportProgress(0.0);
|
reportProgress(0.0);
|
||||||
const tasks = [];
|
const tasks = [];
|
||||||
|
|
108
lib/Stats.js
108
lib/Stats.js
|
@ -212,13 +212,13 @@ class Stats {
|
||||||
text += ` ${locInfo}`;
|
text += ` ${locInfo}`;
|
||||||
}
|
}
|
||||||
if(e.dependencies) {
|
if(e.dependencies) {
|
||||||
e.dependencies.forEach(dep => {
|
for(const dep of e.dependencies) {
|
||||||
if(!dep.loc) return;
|
if(!dep.loc) continue;
|
||||||
if(typeof dep.loc === "string") return;
|
if(typeof dep.loc === "string") continue;
|
||||||
const locInfo = formatLocation(dep.loc);
|
const locInfo = formatLocation(dep.loc);
|
||||||
if(!locInfo) return;
|
if(!locInfo) continue;
|
||||||
text += ` ${locInfo}`;
|
text += ` ${locInfo}`;
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
let current = e.origin;
|
let current = e.origin;
|
||||||
while(current.issuer) {
|
while(current.issuer) {
|
||||||
|
@ -288,12 +288,12 @@ class Stats {
|
||||||
}).filter(createAssetFilter());
|
}).filter(createAssetFilter());
|
||||||
obj.filteredAssets = compilationAssets.length - obj.assets.length;
|
obj.filteredAssets = compilationAssets.length - obj.assets.length;
|
||||||
|
|
||||||
compilation.chunks.forEach(chunk => {
|
for(const chunk of compilation.chunks) {
|
||||||
chunk.files.forEach(asset => {
|
for(const asset of chunk.files) {
|
||||||
if(assetsByFile[asset]) {
|
if(assetsByFile[asset]) {
|
||||||
chunk.ids.forEach(id => {
|
for(const id of chunk.ids) {
|
||||||
assetsByFile[asset].chunks.push(id);
|
assetsByFile[asset].chunks.push(id);
|
||||||
});
|
}
|
||||||
if(chunk.name) {
|
if(chunk.name) {
|
||||||
assetsByFile[asset].chunkNames.push(chunk.name);
|
assetsByFile[asset].chunkNames.push(chunk.name);
|
||||||
if(obj.assetsByChunkName[chunk.name])
|
if(obj.assetsByChunkName[chunk.name])
|
||||||
|
@ -302,8 +302,8 @@ class Stats {
|
||||||
obj.assetsByChunkName[chunk.name] = asset;
|
obj.assetsByChunkName[chunk.name] = asset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
}
|
||||||
obj.assets.sort(sortByField(sortAssets));
|
obj.assets.sort(sortByField(sortAssets));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -649,7 +649,7 @@ class Stats {
|
||||||
color: colors.bold
|
color: colors.bold
|
||||||
}]
|
}]
|
||||||
];
|
];
|
||||||
obj.assets.forEach(asset => {
|
for(const asset of obj.assets) {
|
||||||
t.push([{
|
t.push([{
|
||||||
value: asset.name,
|
value: asset.name,
|
||||||
color: getAssetColor(asset, colors.green)
|
color: getAssetColor(asset, colors.green)
|
||||||
|
@ -669,7 +669,7 @@ class Stats {
|
||||||
value: asset.chunkNames.join(", "),
|
value: asset.chunkNames.join(", "),
|
||||||
color: colors.normal
|
color: colors.normal
|
||||||
}]);
|
}]);
|
||||||
});
|
}
|
||||||
table(t, "rrrlll");
|
table(t, "rrrlll");
|
||||||
}
|
}
|
||||||
if(obj.filteredAssets > 0) {
|
if(obj.filteredAssets > 0) {
|
||||||
|
@ -683,7 +683,7 @@ class Stats {
|
||||||
newline();
|
newline();
|
||||||
}
|
}
|
||||||
if(obj.entrypoints) {
|
if(obj.entrypoints) {
|
||||||
Object.keys(obj.entrypoints).forEach(name => {
|
for(const name of Object.keys(obj.entrypoints)) {
|
||||||
const ep = obj.entrypoints[name];
|
const ep = obj.entrypoints[name];
|
||||||
colors.normal("Entrypoint ");
|
colors.normal("Entrypoint ");
|
||||||
colors.bold(name);
|
colors.bold(name);
|
||||||
|
@ -692,37 +692,37 @@ class Stats {
|
||||||
colors.yellow("[big]");
|
colors.yellow("[big]");
|
||||||
}
|
}
|
||||||
colors.normal(" =");
|
colors.normal(" =");
|
||||||
ep.assets.forEach(asset => {
|
for(const asset of ep.assets) {
|
||||||
colors.normal(" ");
|
colors.normal(" ");
|
||||||
colors.green(asset);
|
colors.green(asset);
|
||||||
});
|
}
|
||||||
newline();
|
newline();
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
const modulesByIdentifier = {};
|
const modulesByIdentifier = {};
|
||||||
if(obj.modules) {
|
if(obj.modules) {
|
||||||
obj.modules.forEach(module => {
|
for(const module of obj.modules) {
|
||||||
modulesByIdentifier[`$${module.identifier}`] = module;
|
modulesByIdentifier[`$${module.identifier}`] = module;
|
||||||
});
|
}
|
||||||
} else if(obj.chunks) {
|
} else if(obj.chunks) {
|
||||||
obj.chunks.forEach(chunk => {
|
for(const chunk of obj.chunks) {
|
||||||
if(chunk.modules) {
|
if(chunk.modules) {
|
||||||
chunk.modules.forEach(module => {
|
for(const module of chunk.modules) {
|
||||||
modulesByIdentifier[`$${module.identifier}`] = module;
|
modulesByIdentifier[`$${module.identifier}`] = module;
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const processModuleAttributes = (module) => {
|
const processModuleAttributes = (module) => {
|
||||||
colors.normal(" ");
|
colors.normal(" ");
|
||||||
colors.normal(SizeFormatHelpers.formatSize(module.size));
|
colors.normal(SizeFormatHelpers.formatSize(module.size));
|
||||||
if(module.chunks) {
|
if(module.chunks) {
|
||||||
module.chunks.forEach(chunk => {
|
for(const chunk of module.chunks) {
|
||||||
colors.normal(" {");
|
colors.normal(" {");
|
||||||
colors.yellow(chunk);
|
colors.yellow(chunk);
|
||||||
colors.normal("}");
|
colors.normal("}");
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
if(typeof module.depth === "number") {
|
if(typeof module.depth === "number") {
|
||||||
colors.normal(` [depth ${module.depth}]`);
|
colors.normal(` [depth ${module.depth}]`);
|
||||||
|
@ -771,14 +771,14 @@ class Stats {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(Array.isArray(module.optimizationBailout)) {
|
if(Array.isArray(module.optimizationBailout)) {
|
||||||
module.optimizationBailout.forEach(item => {
|
for(const item of module.optimizationBailout) {
|
||||||
colors.normal(prefix);
|
colors.normal(prefix);
|
||||||
colors.yellow(item);
|
colors.yellow(item);
|
||||||
newline();
|
newline();
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
if(module.reasons) {
|
if(module.reasons) {
|
||||||
module.reasons.forEach(reason => {
|
for(const reason of module.reasons) {
|
||||||
colors.normal(prefix);
|
colors.normal(prefix);
|
||||||
if(reason.type) {
|
if(reason.type) {
|
||||||
colors.normal(reason.type);
|
colors.normal(reason.type);
|
||||||
|
@ -802,32 +802,32 @@ class Stats {
|
||||||
colors.normal(reason.loc);
|
colors.normal(reason.loc);
|
||||||
}
|
}
|
||||||
newline();
|
newline();
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
if(module.profile) {
|
if(module.profile) {
|
||||||
colors.normal(prefix);
|
colors.normal(prefix);
|
||||||
let sum = 0;
|
let sum = 0;
|
||||||
if(module.issuerPath) {
|
if(module.issuerPath) {
|
||||||
module.issuerPath.forEach(module => {
|
for(const m of module.issuerPath) {
|
||||||
colors.normal("[");
|
colors.normal("[");
|
||||||
colors.normal(module.id);
|
colors.normal(m.id);
|
||||||
colors.normal("] ");
|
colors.normal("] ");
|
||||||
if(module.profile) {
|
if(m.profile) {
|
||||||
const time = (module.profile.factory || 0) + (module.profile.building || 0);
|
const time = (m.profile.factory || 0) + (m.profile.building || 0);
|
||||||
coloredTime(time);
|
coloredTime(time);
|
||||||
sum += time;
|
sum += time;
|
||||||
colors.normal(" ");
|
colors.normal(" ");
|
||||||
}
|
}
|
||||||
colors.normal("-> ");
|
colors.normal("-> ");
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
Object.keys(module.profile).forEach(key => {
|
for(const key of Object.keys(module.profile)) {
|
||||||
colors.normal(`${key}:`);
|
colors.normal(`${key}:`);
|
||||||
const time = module.profile[key];
|
const time = module.profile[key];
|
||||||
coloredTime(time);
|
coloredTime(time);
|
||||||
colors.normal(" ");
|
colors.normal(" ");
|
||||||
sum += time;
|
sum += time;
|
||||||
});
|
}
|
||||||
colors.normal("= ");
|
colors.normal("= ");
|
||||||
coloredTime(sum);
|
coloredTime(sum);
|
||||||
newline();
|
newline();
|
||||||
|
@ -839,7 +839,7 @@ class Stats {
|
||||||
|
|
||||||
const processModulesList = (obj, prefix) => {
|
const processModulesList = (obj, prefix) => {
|
||||||
if(obj.modules) {
|
if(obj.modules) {
|
||||||
obj.modules.forEach(module => {
|
for(const module of obj.modules) {
|
||||||
colors.normal(prefix);
|
colors.normal(prefix);
|
||||||
const name = module.name || module.identifier;
|
const name = module.name || module.identifier;
|
||||||
let contentPrefix = prefix + " ";
|
let contentPrefix = prefix + " ";
|
||||||
|
@ -860,7 +860,7 @@ class Stats {
|
||||||
processModuleAttributes(module);
|
processModuleAttributes(module);
|
||||||
newline();
|
newline();
|
||||||
processModuleContent(module, contentPrefix);
|
processModuleContent(module, contentPrefix);
|
||||||
});
|
}
|
||||||
if(obj.filteredModules > 0) {
|
if(obj.filteredModules > 0) {
|
||||||
colors.normal(prefix);
|
colors.normal(prefix);
|
||||||
colors.normal(" ");
|
colors.normal(" ");
|
||||||
|
@ -876,7 +876,7 @@ class Stats {
|
||||||
};
|
};
|
||||||
|
|
||||||
if(obj.chunks) {
|
if(obj.chunks) {
|
||||||
obj.chunks.forEach(chunk => {
|
for(const chunk of obj.chunks) {
|
||||||
colors.normal("chunk ");
|
colors.normal("chunk ");
|
||||||
if(chunk.id < 1000) colors.normal(" ");
|
if(chunk.id < 1000) colors.normal(" ");
|
||||||
if(chunk.id < 100) colors.normal(" ");
|
if(chunk.id < 100) colors.normal(" ");
|
||||||
|
@ -892,21 +892,21 @@ class Stats {
|
||||||
}
|
}
|
||||||
colors.normal(" ");
|
colors.normal(" ");
|
||||||
colors.normal(SizeFormatHelpers.formatSize(chunk.size));
|
colors.normal(SizeFormatHelpers.formatSize(chunk.size));
|
||||||
chunk.parents.forEach(id => {
|
for(const id of chunk.parents) {
|
||||||
colors.normal(" <{");
|
colors.normal(" <{");
|
||||||
colors.yellow(id);
|
colors.yellow(id);
|
||||||
colors.normal("}>");
|
colors.normal("}>");
|
||||||
});
|
}
|
||||||
chunk.siblings.forEach(id => {
|
for(const id of chunk.siblings) {
|
||||||
colors.normal(" ={");
|
colors.normal(" ={");
|
||||||
colors.yellow(id);
|
colors.yellow(id);
|
||||||
colors.normal("}=");
|
colors.normal("}=");
|
||||||
});
|
}
|
||||||
chunk.children.forEach(id => {
|
for(const id of chunk.children) {
|
||||||
colors.normal(" >{");
|
colors.normal(" >{");
|
||||||
colors.yellow(id);
|
colors.yellow(id);
|
||||||
colors.normal("}<");
|
colors.normal("}<");
|
||||||
});
|
}
|
||||||
if(chunk.entry) {
|
if(chunk.entry) {
|
||||||
colors.yellow(" [entry]");
|
colors.yellow(" [entry]");
|
||||||
} else if(chunk.initial) {
|
} else if(chunk.initial) {
|
||||||
|
@ -923,7 +923,7 @@ class Stats {
|
||||||
}
|
}
|
||||||
newline();
|
newline();
|
||||||
if(chunk.origins) {
|
if(chunk.origins) {
|
||||||
chunk.origins.forEach(origin => {
|
for(const origin of chunk.origins) {
|
||||||
colors.normal(" > ");
|
colors.normal(" > ");
|
||||||
if(origin.reasons && origin.reasons.length) {
|
if(origin.reasons && origin.reasons.length) {
|
||||||
colors.yellow(origin.reasons.join(" "));
|
colors.yellow(origin.reasons.join(" "));
|
||||||
|
@ -947,30 +947,30 @@ class Stats {
|
||||||
colors.normal(origin.loc);
|
colors.normal(origin.loc);
|
||||||
}
|
}
|
||||||
newline();
|
newline();
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
processModulesList(chunk, " ");
|
processModulesList(chunk, " ");
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
processModulesList(obj, "");
|
processModulesList(obj, "");
|
||||||
|
|
||||||
if(obj._showWarnings && obj.warnings) {
|
if(obj._showWarnings && obj.warnings) {
|
||||||
obj.warnings.forEach(warning => {
|
for(const warning of obj.warnings) {
|
||||||
newline();
|
newline();
|
||||||
colors.yellow(`WARNING in ${warning}`);
|
colors.yellow(`WARNING in ${warning}`);
|
||||||
newline();
|
newline();
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
if(obj._showErrors && obj.errors) {
|
if(obj._showErrors && obj.errors) {
|
||||||
obj.errors.forEach(error => {
|
for(const error of obj.errors) {
|
||||||
newline();
|
newline();
|
||||||
colors.red(`ERROR in ${error}`);
|
colors.red(`ERROR in ${error}`);
|
||||||
newline();
|
newline();
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
if(obj.children) {
|
if(obj.children) {
|
||||||
obj.children.forEach(child => {
|
for(const child of obj.children) {
|
||||||
const childString = Stats.jsonToString(child, useColors);
|
const childString = Stats.jsonToString(child, useColors);
|
||||||
if(childString) {
|
if(childString) {
|
||||||
if(child.name) {
|
if(child.name) {
|
||||||
|
@ -985,7 +985,7 @@ class Stats {
|
||||||
buf.push(childString.replace(/\n/g, "\n "));
|
buf.push(childString.replace(/\n/g, "\n "));
|
||||||
newline();
|
newline();
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
if(obj.needAdditionalPass) {
|
if(obj.needAdditionalPass) {
|
||||||
colors.yellow("Compilation needs an additional pass and will compile again.");
|
colors.yellow("Compilation needs an additional pass and will compile again.");
|
||||||
|
|
|
@ -101,10 +101,10 @@ module.exports = class Template {
|
||||||
return false;
|
return false;
|
||||||
var maxId = -Infinity;
|
var maxId = -Infinity;
|
||||||
var minId = Infinity;
|
var minId = Infinity;
|
||||||
modules.forEach(module => {
|
for(const module of modules) {
|
||||||
if(maxId < module.id) maxId = module.id;
|
if(maxId < module.id) maxId = module.id;
|
||||||
if(minId > module.id) minId = module.id;
|
if(minId > module.id) minId = module.id;
|
||||||
});
|
}
|
||||||
if(minId < 16 + ("" + minId).length) {
|
if(minId < 16 + ("" + minId).length) {
|
||||||
// add minId x ',' instead of 'Array(minId).concat(...)'
|
// add minId x ',' instead of 'Array(minId).concat(...)'
|
||||||
minId = 0;
|
minId = 0;
|
||||||
|
@ -137,12 +137,12 @@ module.exports = class Template {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
if(removedModules && removedModules.length > 0) {
|
if(removedModules && removedModules.length > 0) {
|
||||||
removedModules.forEach(id => {
|
for(const id of removedModules) {
|
||||||
allModules.push({
|
allModules.push({
|
||||||
id: id,
|
id: id,
|
||||||
source: "false"
|
source: "false"
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
var bounds = Template.getModulesArrayBounds(allModules);
|
var bounds = Template.getModulesArrayBounds(allModules);
|
||||||
|
|
||||||
|
@ -153,9 +153,9 @@ module.exports = class Template {
|
||||||
if(minId !== 0) source.add("Array(" + minId + ").concat(");
|
if(minId !== 0) source.add("Array(" + minId + ").concat(");
|
||||||
source.add("[\n");
|
source.add("[\n");
|
||||||
const modules = new Map();
|
const modules = new Map();
|
||||||
allModules.forEach(module => {
|
for(const module of allModules) {
|
||||||
modules.set(module.id, module);
|
modules.set(module.id, module);
|
||||||
});
|
}
|
||||||
for(var idx = minId; idx <= maxId; idx++) {
|
for(var idx = minId; idx <= maxId; idx++) {
|
||||||
var module = modules.get(idx);
|
var module = modules.get(idx);
|
||||||
if(idx !== minId) source.add(",\n");
|
if(idx !== minId) source.add(",\n");
|
||||||
|
|
|
@ -51,13 +51,13 @@ class UmdMainTemplatePlugin {
|
||||||
const optionalExternals = [];
|
const optionalExternals = [];
|
||||||
let requiredExternals = [];
|
let requiredExternals = [];
|
||||||
if(this.optionalAmdExternalAsGlobal) {
|
if(this.optionalAmdExternalAsGlobal) {
|
||||||
externals.forEach(m => {
|
for(const m of externals) {
|
||||||
if(m.optional) {
|
if(m.optional) {
|
||||||
optionalExternals.push(m);
|
optionalExternals.push(m);
|
||||||
} else {
|
} else {
|
||||||
requiredExternals.push(m);
|
requiredExternals.push(m);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
externals = requiredExternals.concat(optionalExternals);
|
externals = requiredExternals.concat(optionalExternals);
|
||||||
} else {
|
} else {
|
||||||
requiredExternals = externals;
|
requiredExternals = externals;
|
||||||
|
|
|
@ -11,7 +11,7 @@ class WarnCaseSensitiveModulesPlugin {
|
||||||
compiler.hooks.compilation.tap("WarnCaseSensitiveModulesPlugin", (compilation) => {
|
compiler.hooks.compilation.tap("WarnCaseSensitiveModulesPlugin", (compilation) => {
|
||||||
compilation.hooks.seal.tap("WarnCaseSensitiveModulesPlugin", () => {
|
compilation.hooks.seal.tap("WarnCaseSensitiveModulesPlugin", () => {
|
||||||
const moduleWithoutCase = new Map();
|
const moduleWithoutCase = new Map();
|
||||||
compilation.modules.forEach(module => {
|
for(const module of compilation.modules) {
|
||||||
const identifier = module.identifier().toLowerCase();
|
const identifier = module.identifier().toLowerCase();
|
||||||
const array = moduleWithoutCase.get(identifier);
|
const array = moduleWithoutCase.get(identifier);
|
||||||
if(array) {
|
if(array) {
|
||||||
|
@ -19,7 +19,7 @@ class WarnCaseSensitiveModulesPlugin {
|
||||||
} else {
|
} else {
|
||||||
moduleWithoutCase.set(identifier, [module]);
|
moduleWithoutCase.set(identifier, [module]);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
for(const pair of moduleWithoutCase) {
|
for(const pair of moduleWithoutCase) {
|
||||||
const array = pair[1];
|
const array = pair[1];
|
||||||
if(array.length > 1)
|
if(array.length > 1)
|
||||||
|
|
|
@ -39,13 +39,13 @@ class IgnoringWatchFileSystem {
|
||||||
const watcher = this.wfs.watch(files.filter(notIgnored), dirs.filter(notIgnored), missing, startTime, options, (err, filesModified, dirsModified, missingModified, fileTimestamps, dirTimestamps) => {
|
const watcher = this.wfs.watch(files.filter(notIgnored), dirs.filter(notIgnored), missing, startTime, options, (err, filesModified, dirsModified, missingModified, fileTimestamps, dirTimestamps) => {
|
||||||
if(err) return callback(err);
|
if(err) return callback(err);
|
||||||
|
|
||||||
ignoredFiles.forEach(path => {
|
for(const path of ignoredFiles) {
|
||||||
fileTimestamps.set(path, 1);
|
fileTimestamps.set(path, 1);
|
||||||
});
|
}
|
||||||
|
|
||||||
ignoredDirs.forEach(path => {
|
for(const path of ignoredDirs) {
|
||||||
dirTimestamps.set(path, 1);
|
dirTimestamps.set(path, 1);
|
||||||
});
|
}
|
||||||
|
|
||||||
callback(err, filesModified, dirsModified, missingModified, fileTimestamps, dirTimestamps);
|
callback(err, filesModified, dirsModified, missingModified, fileTimestamps, dirTimestamps);
|
||||||
}, callbackUndelayed);
|
}, callbackUndelayed);
|
||||||
|
@ -55,16 +55,16 @@ class IgnoringWatchFileSystem {
|
||||||
pause: () => watcher.pause(),
|
pause: () => watcher.pause(),
|
||||||
getContextTimestamps: () => {
|
getContextTimestamps: () => {
|
||||||
const dirTimestamps = watcher.getContextTimestamps();
|
const dirTimestamps = watcher.getContextTimestamps();
|
||||||
ignoredDirs.forEach(path => {
|
for(const path of ignoredDirs) {
|
||||||
dirTimestamps.set(path, 1);
|
dirTimestamps.set(path, 1);
|
||||||
});
|
}
|
||||||
return dirTimestamps;
|
return dirTimestamps;
|
||||||
},
|
},
|
||||||
getFileTimestamps: () => {
|
getFileTimestamps: () => {
|
||||||
const fileTimestamps = watcher.getFileTimestamps();
|
const fileTimestamps = watcher.getFileTimestamps();
|
||||||
ignoredFiles.forEach(path => {
|
for(const path of ignoredFiles) {
|
||||||
fileTimestamps.set(path, 1);
|
fileTimestamps.set(path, 1);
|
||||||
});
|
}
|
||||||
return fileTimestamps;
|
return fileTimestamps;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -98,7 +98,7 @@ class Watching {
|
||||||
if(!this.closed) {
|
if(!this.closed) {
|
||||||
this.watch(Array.from(compilation.fileDependencies), Array.from(compilation.contextDependencies), Array.from(compilation.missingDependencies));
|
this.watch(Array.from(compilation.fileDependencies), Array.from(compilation.contextDependencies), Array.from(compilation.missingDependencies));
|
||||||
}
|
}
|
||||||
this.callbacks.forEach(cb => cb());
|
for(const cb of this.callbacks) cb();
|
||||||
this.callbacks.length = 0;
|
this.callbacks.length = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,16 +68,16 @@ class AMDRequireDependenciesBlockParserPlugin {
|
||||||
|
|
||||||
const processArray = (expr, param) => {
|
const processArray = (expr, param) => {
|
||||||
if(param.isArray()) {
|
if(param.isArray()) {
|
||||||
param.items.forEach((param) => {
|
for(const p of param.items) {
|
||||||
const result = processItem(expr, param);
|
const result = processItem(expr, p);
|
||||||
if(result === undefined) {
|
if(result === undefined) {
|
||||||
processContext(expr, param);
|
processContext(expr, p);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
return true;
|
return true;
|
||||||
} else if(param.isConstArray()) {
|
} else if(param.isConstArray()) {
|
||||||
const deps = [];
|
const deps = [];
|
||||||
param.array.forEach((request) => {
|
for(const request of param.array) {
|
||||||
let dep, localModule;
|
let dep, localModule;
|
||||||
if(request === "require") {
|
if(request === "require") {
|
||||||
dep = "__webpack_require__";
|
dep = "__webpack_require__";
|
||||||
|
@ -94,7 +94,7 @@ class AMDRequireDependenciesBlockParserPlugin {
|
||||||
parser.state.current.addDependency(dep);
|
parser.state.current.addDependency(dep);
|
||||||
}
|
}
|
||||||
deps.push(dep);
|
deps.push(dep);
|
||||||
});
|
}
|
||||||
const dep = new AMDRequireArrayDependency(deps, param.range);
|
const dep = new AMDRequireArrayDependency(deps, param.range);
|
||||||
dep.loc = expr.loc;
|
dep.loc = expr.loc;
|
||||||
dep.optional = !!parser.scope.inTry;
|
dep.optional = !!parser.scope.inTry;
|
||||||
|
@ -104,12 +104,12 @@ class AMDRequireDependenciesBlockParserPlugin {
|
||||||
};
|
};
|
||||||
const processItem = (expr, param) => {
|
const processItem = (expr, param) => {
|
||||||
if(param.isConditional()) {
|
if(param.isConditional()) {
|
||||||
param.options.forEach((param) => {
|
for(const p of param.options) {
|
||||||
const result = processItem(expr, param);
|
const result = processItem(expr, p);
|
||||||
if(result === undefined) {
|
if(result === undefined) {
|
||||||
processContext(expr, param);
|
processContext(expr, p);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
return true;
|
return true;
|
||||||
} else if(param.isString()) {
|
} else if(param.isString()) {
|
||||||
let dep, localModule;
|
let dep, localModule;
|
||||||
|
|
|
@ -62,12 +62,12 @@ class CommonJsRequireDependencyParserPlugin {
|
||||||
const dep = new RequireHeaderDependency(expr.callee.range);
|
const dep = new RequireHeaderDependency(expr.callee.range);
|
||||||
dep.loc = expr.loc;
|
dep.loc = expr.loc;
|
||||||
parser.state.current.addDependency(dep);
|
parser.state.current.addDependency(dep);
|
||||||
param.options.forEach(param => {
|
for(const p of param.options) {
|
||||||
const result = processItem(expr, param);
|
const result = processItem(expr, p);
|
||||||
if(result === undefined) {
|
if(result === undefined) {
|
||||||
isExpression = true;
|
isExpression = true;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
if(isExpression) {
|
if(isExpression) {
|
||||||
parser.state.current.dependencies.length = prevLength;
|
parser.state.current.dependencies.length = prevLength;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -67,12 +67,12 @@ module.exports = class HarmonyDetectionParserPlugin {
|
||||||
};
|
};
|
||||||
|
|
||||||
const nonHarmonyIdentifiers = ["define", "exports"];
|
const nonHarmonyIdentifiers = ["define", "exports"];
|
||||||
nonHarmonyIdentifiers.forEach(identifer => {
|
for(const identifer of nonHarmonyIdentifiers) {
|
||||||
parser.hooks.evaluateTypeof.for(identifer).tap("HarmonyDetectionParserPlugin", nullInHarmony);
|
parser.hooks.evaluateTypeof.for(identifer).tap("HarmonyDetectionParserPlugin", nullInHarmony);
|
||||||
parser.hooks.typeof.for(identifer).tap("HarmonyDetectionParserPlugin", skipInHarmony);
|
parser.hooks.typeof.for(identifer).tap("HarmonyDetectionParserPlugin", skipInHarmony);
|
||||||
parser.hooks.evaluate.for(identifer).tap("HarmonyDetectionParserPlugin", nullInHarmony);
|
parser.hooks.evaluate.for(identifer).tap("HarmonyDetectionParserPlugin", nullInHarmony);
|
||||||
parser.hooks.expression.for(identifer).tap("HarmonyDetectionParserPlugin", skipInHarmony);
|
parser.hooks.expression.for(identifer).tap("HarmonyDetectionParserPlugin", skipInHarmony);
|
||||||
parser.hooks.call.for(identifer).tap("HarmonyDetectionParserPlugin", skipInHarmony);
|
parser.hooks.call.for(identifer).tap("HarmonyDetectionParserPlugin", skipInHarmony);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -44,10 +44,14 @@ class LoaderPlugin {
|
||||||
source = moduleSource.source();
|
source = moduleSource.source();
|
||||||
}
|
}
|
||||||
if(dep.module.buildInfo.fileDependencies) {
|
if(dep.module.buildInfo.fileDependencies) {
|
||||||
dep.module.buildInfo.fileDependencies.forEach(dep => loaderContext.addDependency(dep));
|
for(const d of dep.module.buildInfo.fileDependencies) {
|
||||||
|
loaderContext.addDependency(d);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(dep.module.buildInfo.contextDependencies) {
|
if(dep.module.buildInfo.contextDependencies) {
|
||||||
dep.module.buildInfo.contextDependencies.forEach(dep => loaderContext.addContextDependency(dep));
|
for(const d of dep.module.buildInfo.contextDependencies) {
|
||||||
|
loaderContext.addContextDependency(d);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return callback(null, source, map, dep.module);
|
return callback(null, source, map, dep.module);
|
||||||
});
|
});
|
||||||
|
|
|
@ -60,7 +60,7 @@ module.exports = class RequireEnsureDependenciesBlockParserPlugin {
|
||||||
try {
|
try {
|
||||||
let failed = false;
|
let failed = false;
|
||||||
parser.inScope([], () => {
|
parser.inScope([], () => {
|
||||||
dependenciesItems.forEach(ee => {
|
for(const ee of dependenciesItems) {
|
||||||
if(ee.isString()) {
|
if(ee.isString()) {
|
||||||
const edep = new RequireEnsureItemDependency(ee.string, ee.range);
|
const edep = new RequireEnsureItemDependency(ee.string, ee.range);
|
||||||
edep.loc = dep.loc;
|
edep.loc = dep.loc;
|
||||||
|
@ -68,7 +68,7 @@ module.exports = class RequireEnsureDependenciesBlockParserPlugin {
|
||||||
} else {
|
} else {
|
||||||
failed = true;
|
failed = true;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
if(failed) {
|
if(failed) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -21,12 +21,12 @@ class RequireResolveDependencyParserPlugin {
|
||||||
if(expr.arguments.length !== 1) return;
|
if(expr.arguments.length !== 1) return;
|
||||||
const param = parser.evaluateExpression(expr.arguments[0]);
|
const param = parser.evaluateExpression(expr.arguments[0]);
|
||||||
if(param.isConditional()) {
|
if(param.isConditional()) {
|
||||||
param.options.forEach((option) => {
|
for(const option of param.options) {
|
||||||
const result = processItem(expr, option, weak);
|
const result = processItem(expr, option, weak);
|
||||||
if(result === undefined) {
|
if(result === undefined) {
|
||||||
processContext(expr, option, weak);
|
processContext(expr, option, weak);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
const dep = new RequireResolveHeaderDependency(expr.callee.range);
|
const dep = new RequireResolveHeaderDependency(expr.callee.range);
|
||||||
dep.loc = expr.loc;
|
dep.loc = expr.loc;
|
||||||
parser.state.current.addDependency(dep);
|
parser.state.current.addDependency(dep);
|
||||||
|
|
|
@ -87,10 +87,10 @@ module.exports = class NodeMainTemplatePlugin {
|
||||||
hash: `" + ${JSON.stringify(chunkMaps.hash)}[chunkId] + "`,
|
hash: `" + ${JSON.stringify(chunkMaps.hash)}[chunkId] + "`,
|
||||||
hashWithLength: (length) => {
|
hashWithLength: (length) => {
|
||||||
const shortChunkHashMap = {};
|
const shortChunkHashMap = {};
|
||||||
Object.keys(chunkMaps.hash).forEach((chunkId) => {
|
for(const chunkId of Object.keys(chunkMaps.hash)) {
|
||||||
if(typeof chunkMaps.hash[chunkId] === "string")
|
if(typeof chunkMaps.hash[chunkId] === "string")
|
||||||
shortChunkHashMap[chunkId] = chunkMaps.hash[chunkId].substr(0, length);
|
shortChunkHashMap[chunkId] = chunkMaps.hash[chunkId].substr(0, length);
|
||||||
});
|
}
|
||||||
return `" + ${JSON.stringify(shortChunkHashMap)}[chunkId] + "`;
|
return `" + ${JSON.stringify(shortChunkHashMap)}[chunkId] + "`;
|
||||||
},
|
},
|
||||||
name: `" + (${JSON.stringify(chunkMaps.name)}[chunkId]||chunkId) + "`
|
name: `" + (${JSON.stringify(chunkMaps.name)}[chunkId]||chunkId) + "`
|
||||||
|
@ -134,10 +134,10 @@ module.exports = class NodeMainTemplatePlugin {
|
||||||
hash: `" + ${JSON.stringify(chunkMaps.hash)}[chunkId] + "`,
|
hash: `" + ${JSON.stringify(chunkMaps.hash)}[chunkId] + "`,
|
||||||
hashWithLength: (length) => {
|
hashWithLength: (length) => {
|
||||||
const shortChunkHashMap = {};
|
const shortChunkHashMap = {};
|
||||||
Object.keys(chunkMaps.hash).forEach((chunkId) => {
|
for(const chunkId of Object.keys(chunkMaps.hash)) {
|
||||||
if(typeof chunkMaps.hash[chunkId] === "string")
|
if(typeof chunkMaps.hash[chunkId] === "string")
|
||||||
shortChunkHashMap[chunkId] = chunkMaps.hash[chunkId].substr(0, length);
|
shortChunkHashMap[chunkId] = chunkMaps.hash[chunkId].substr(0, length);
|
||||||
});
|
}
|
||||||
return `" + ${JSON.stringify(shortChunkHashMap)}[chunkId] + "`;
|
return `" + ${JSON.stringify(shortChunkHashMap)}[chunkId] + "`;
|
||||||
},
|
},
|
||||||
name: `" + (${JSON.stringify(chunkMaps.name)}[chunkId]||chunkId) + "`
|
name: `" + (${JSON.stringify(chunkMaps.name)}[chunkId]||chunkId) + "`
|
||||||
|
@ -172,10 +172,10 @@ module.exports = class NodeMainTemplatePlugin {
|
||||||
hash: `" + ${JSON.stringify(chunkMaps.hash)}[chunkId] + "`,
|
hash: `" + ${JSON.stringify(chunkMaps.hash)}[chunkId] + "`,
|
||||||
hashWithLength: (length) => {
|
hashWithLength: (length) => {
|
||||||
const shortChunkHashMap = {};
|
const shortChunkHashMap = {};
|
||||||
Object.keys(chunkMaps.hash).forEach((chunkId) => {
|
for(const chunkId of Object.keys(chunkMaps.hash)) {
|
||||||
if(typeof chunkMaps.hash[chunkId] === "string")
|
if(typeof chunkMaps.hash[chunkId] === "string")
|
||||||
shortChunkHashMap[chunkId] = chunkMaps.hash[chunkId].substr(0, length);
|
shortChunkHashMap[chunkId] = chunkMaps.hash[chunkId].substr(0, length);
|
||||||
});
|
}
|
||||||
return `" + ${JSON.stringify(shortChunkHashMap)}[chunkId] + "`;
|
return `" + ${JSON.stringify(shortChunkHashMap)}[chunkId] + "`;
|
||||||
},
|
},
|
||||||
name: `" + (${JSON.stringify(chunkMaps.name)}[chunkId]||chunkId) + "`
|
name: `" + (${JSON.stringify(chunkMaps.name)}[chunkId]||chunkId) + "`
|
||||||
|
|
|
@ -76,7 +76,7 @@ module.exports = class NodeSourcePlugin {
|
||||||
normalModuleFactory.hooks.parser.for("javascript/esm").tap("NodeSourcePlugin", handler);
|
normalModuleFactory.hooks.parser.for("javascript/esm").tap("NodeSourcePlugin", handler);
|
||||||
});
|
});
|
||||||
compiler.hooks.afterResolvers.tap("NodeSourcePlugin", (compiler) => {
|
compiler.hooks.afterResolvers.tap("NodeSourcePlugin", (compiler) => {
|
||||||
Object.keys(nodeLibsBrowser).forEach((lib) => {
|
for(const lib of Object.keys(nodeLibsBrowser)) {
|
||||||
if(options[lib] !== false) {
|
if(options[lib] !== false) {
|
||||||
compiler.resolverFactory.hooks.resolver.for("normal").tap("NodeSourcePlugin", resolver => {
|
compiler.resolverFactory.hooks.resolver.for("normal").tap("NodeSourcePlugin", resolver => {
|
||||||
new AliasPlugin("described-resolve", {
|
new AliasPlugin("described-resolve", {
|
||||||
|
@ -86,7 +86,7 @@ module.exports = class NodeSourcePlugin {
|
||||||
}, "resolve").apply(resolver);
|
}, "resolve").apply(resolver);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -29,10 +29,10 @@ class ReadFileCompileWasmMainTemplatePlugin {
|
||||||
hash: `" + ${JSON.stringify(chunkModuleMaps.hash)}[wasmModuleId] + "`,
|
hash: `" + ${JSON.stringify(chunkModuleMaps.hash)}[wasmModuleId] + "`,
|
||||||
hashWithLength(length) {
|
hashWithLength(length) {
|
||||||
const shortChunkHashMap = Object.create(null);
|
const shortChunkHashMap = Object.create(null);
|
||||||
Object.keys(chunkModuleMaps.hash).forEach(wasmModuleId => {
|
for(const wasmModuleId of Object.keys(chunkModuleMaps.hash)) {
|
||||||
if(typeof chunkModuleMaps.hash[wasmModuleId] === "string")
|
if(typeof chunkModuleMaps.hash[wasmModuleId] === "string")
|
||||||
shortChunkHashMap[wasmModuleId] = chunkModuleMaps.hash[wasmModuleId].substr(0, length);
|
shortChunkHashMap[wasmModuleId] = chunkModuleMaps.hash[wasmModuleId].substr(0, length);
|
||||||
});
|
}
|
||||||
return `" + ${JSON.stringify(shortChunkHashMap)}[wasmModuleId] + "`;
|
return `" + ${JSON.stringify(shortChunkHashMap)}[wasmModuleId] + "`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ class AggressiveMergingPlugin {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
combinations.forEach((pair) => {
|
for(const pair of combinations) {
|
||||||
const a = pair.b.size({
|
const a = pair.b.size({
|
||||||
chunkOverhead: 0
|
chunkOverhead: 0
|
||||||
});
|
});
|
||||||
|
@ -51,7 +51,7 @@ class AggressiveMergingPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
pair.improvement = (a + b) / newSize;
|
pair.improvement = (a + b) / newSize;
|
||||||
});
|
}
|
||||||
combinations = combinations.filter((pair) => {
|
combinations = combinations.filter((pair) => {
|
||||||
return pair.improvement !== false;
|
return pair.improvement !== false;
|
||||||
});
|
});
|
||||||
|
|
|
@ -47,11 +47,11 @@ class AggressiveSplittingPlugin {
|
||||||
// Precompute stuff
|
// Precompute stuff
|
||||||
const nameToModuleMap = new Map();
|
const nameToModuleMap = new Map();
|
||||||
const moduleToNameMap = new Map();
|
const moduleToNameMap = new Map();
|
||||||
compilation.modules.forEach(m => {
|
for(const m of compilation.modules) {
|
||||||
const name = identifierUtils.makePathsRelative(compiler.context, m.identifier(), compilation.cache);
|
const name = identifierUtils.makePathsRelative(compiler.context, m.identifier(), compilation.cache);
|
||||||
nameToModuleMap.set(name, m);
|
nameToModuleMap.set(name, m);
|
||||||
moduleToNameMap.set(m, name);
|
moduleToNameMap.set(m, name);
|
||||||
});
|
}
|
||||||
|
|
||||||
// Check used chunk ids
|
// Check used chunk ids
|
||||||
const usedIds = new Set();
|
const usedIds = new Set();
|
||||||
|
@ -186,7 +186,7 @@ class AggressiveSplittingPlugin {
|
||||||
|
|
||||||
// Check if some splittings are invalid
|
// Check if some splittings are invalid
|
||||||
// We remove invalid splittings and try again
|
// We remove invalid splittings and try again
|
||||||
compilation.chunks.forEach((chunk) => {
|
for(const chunk of compilation.chunks) {
|
||||||
const splitData = chunkSplitDataMap.get(chunk);
|
const splitData = chunkSplitDataMap.get(chunk);
|
||||||
if(splitData !== undefined) {
|
if(splitData !== undefined) {
|
||||||
if(splitData.hash && chunk.hash !== splitData.hash) {
|
if(splitData.hash && chunk.hash !== splitData.hash) {
|
||||||
|
@ -195,7 +195,7 @@ class AggressiveSplittingPlugin {
|
||||||
invalidSplits.add(splitData);
|
invalidSplits.add(splitData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
if(invalidSplits.size > 0) {
|
if(invalidSplits.size > 0) {
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ class AggressiveSplittingPlugin {
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// set hash and id values on all (new) splittings
|
// set hash and id values on all (new) splittings
|
||||||
compilation.chunks.forEach((chunk) => {
|
for(const chunk of compilation.chunks) {
|
||||||
const splitData = chunkSplitDataMap.get(chunk);
|
const splitData = chunkSplitDataMap.get(chunk);
|
||||||
if(splitData !== undefined) {
|
if(splitData !== undefined) {
|
||||||
splitData.hash = chunk.hash;
|
splitData.hash = chunk.hash;
|
||||||
|
@ -214,7 +214,7 @@ class AggressiveSplittingPlugin {
|
||||||
// set flag for stats
|
// set flag for stats
|
||||||
chunk.recorded = true;
|
chunk.recorded = true;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
// Also add all unused historial splits (after the used ones)
|
// Also add all unused historial splits (after the used ones)
|
||||||
// They can still be used in some future compilation
|
// They can still be used in some future compilation
|
||||||
|
|
|
@ -118,7 +118,9 @@ const getSymbolsFromScope = (s, untilScope) => {
|
||||||
let scope = s;
|
let scope = s;
|
||||||
while(scope) {
|
while(scope) {
|
||||||
if(untilScope === scope) break;
|
if(untilScope === scope) break;
|
||||||
scope.variables.forEach(variable => allUsedNames.add(variable.name));
|
for(const variable of scope.variables) {
|
||||||
|
allUsedNames.add(variable.name);
|
||||||
|
}
|
||||||
scope = scope.upper;
|
scope = scope.upper;
|
||||||
}
|
}
|
||||||
return allUsedNames;
|
return allUsedNames;
|
||||||
|
@ -237,16 +239,25 @@ class ConcatenatedModule extends Module {
|
||||||
const m = info.module;
|
const m = info.module;
|
||||||
|
|
||||||
// populate dependencies
|
// populate dependencies
|
||||||
m.dependencies.filter(dep => !(dep instanceof HarmonyImportDependency) || !modulesSet.has(dep.module))
|
for(const d of m.dependencies.filter(dep => !(dep instanceof HarmonyImportDependency) || !modulesSet.has(dep.module))) {
|
||||||
.forEach(d => this.dependencies.push(d));
|
this.dependencies.push(d);
|
||||||
|
}
|
||||||
// populate file dependencies
|
// populate file dependencies
|
||||||
if(m.buildInfo.fileDependencies) m.buildInfo.fileDependencies.forEach(file => this.buildInfo.fileDependencies.add(file));
|
if(m.buildInfo.fileDependencies) {
|
||||||
|
for(const file of m.buildInfo.fileDependencies) {
|
||||||
|
this.buildInfo.fileDependencies.add(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
// populate context dependencies
|
// populate context dependencies
|
||||||
if(m.buildInfo.contextDependencies) m.buildInfo.contextDependencies.forEach(context => this.buildInfo.contextDependencies.add(context));
|
if(m.buildInfo.contextDependencies) {
|
||||||
|
for(const context of m.buildInfo.contextDependencies) {
|
||||||
|
this.buildInfo.contextDependencies.add(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
// populate warnings
|
// populate warnings
|
||||||
m.warnings.forEach(warning => this.warnings.push(warning));
|
for(const warning of m.warnings) this.warnings.push(warning);
|
||||||
// populate errors
|
// populate errors
|
||||||
m.errors.forEach(error => this.errors.push(error));
|
for(const error of m.errors) this.errors.push(error);
|
||||||
|
|
||||||
if(m.buildInfo.assets) {
|
if(m.buildInfo.assets) {
|
||||||
if(this.buildInfo.assets === undefined)
|
if(this.buildInfo.assets === undefined)
|
||||||
|
@ -363,7 +374,7 @@ class ConcatenatedModule extends Module {
|
||||||
{
|
{
|
||||||
const exportMap = new Map();
|
const exportMap = new Map();
|
||||||
const reexportMap = new Map();
|
const reexportMap = new Map();
|
||||||
info.module.dependencies.forEach(dep => {
|
for(const dep of info.module.dependencies) {
|
||||||
if(dep instanceof HarmonyExportSpecifierDependency) {
|
if(dep instanceof HarmonyExportSpecifierDependency) {
|
||||||
if(!exportMap.has(dep.name))
|
if(!exportMap.has(dep.name))
|
||||||
exportMap.set(dep.name, dep.id);
|
exportMap.set(dep.name, dep.id);
|
||||||
|
@ -391,9 +402,9 @@ class ConcatenatedModule extends Module {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if(importedModule) {
|
} else if(importedModule) {
|
||||||
importedModule.buildMeta.providedExports.forEach(name => {
|
for(const name of importedModule.buildMeta.providedExports) {
|
||||||
if(dep.activeExports.has(name) || name === "default")
|
if(dep.activeExports.has(name) || name === "default")
|
||||||
return;
|
continue;
|
||||||
if(!reexportMap.has(name)) {
|
if(!reexportMap.has(name)) {
|
||||||
reexportMap.set(name, {
|
reexportMap.set(name, {
|
||||||
module: importedModule,
|
module: importedModule,
|
||||||
|
@ -401,10 +412,10 @@ class ConcatenatedModule extends Module {
|
||||||
dependency: dep
|
dependency: dep
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
return {
|
return {
|
||||||
type: "concatenated",
|
type: "concatenated",
|
||||||
module: info.module,
|
module: info.module,
|
||||||
|
@ -439,7 +450,9 @@ class ConcatenatedModule extends Module {
|
||||||
|
|
||||||
// Create mapping from module to info
|
// Create mapping from module to info
|
||||||
const moduleToInfoMap = new Map();
|
const moduleToInfoMap = new Map();
|
||||||
modulesWithInfo.forEach(m => moduleToInfoMap.set(m.module, m));
|
for(const m of modulesWithInfo) {
|
||||||
|
moduleToInfoMap.set(m.module, m);
|
||||||
|
}
|
||||||
|
|
||||||
// Configure template decorators for dependencies
|
// Configure template decorators for dependencies
|
||||||
const innerDependencyTemplates = new Map(dependencyTemplates);
|
const innerDependencyTemplates = new Map(dependencyTemplates);
|
||||||
|
@ -475,7 +488,7 @@ class ConcatenatedModule extends Module {
|
||||||
|
|
||||||
// Generate source code and analyse scopes
|
// Generate source code and analyse scopes
|
||||||
// Prepare a ReplaceSource for the final source
|
// Prepare a ReplaceSource for the final source
|
||||||
modulesWithInfo.forEach(info => {
|
for(const info of modulesWithInfo) {
|
||||||
if(info.type === "concatenated") {
|
if(info.type === "concatenated") {
|
||||||
const m = info.module;
|
const m = info.module;
|
||||||
const source = m.source(innerDependencyTemplates, runtimeTemplate);
|
const source = m.source(innerDependencyTemplates, runtimeTemplate);
|
||||||
|
@ -509,7 +522,7 @@ class ConcatenatedModule extends Module {
|
||||||
info.globalScope = globalScope;
|
info.globalScope = globalScope;
|
||||||
info.moduleScope = moduleScope;
|
info.moduleScope = moduleScope;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
// List of all used names to avoid conflicts
|
// List of all used names to avoid conflicts
|
||||||
const allUsedNames = new Set([
|
const allUsedNames = new Set([
|
||||||
|
@ -546,9 +559,9 @@ class ConcatenatedModule extends Module {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// get all global names
|
// get all global names
|
||||||
modulesWithInfo.forEach(info => {
|
for(const info of modulesWithInfo) {
|
||||||
if(info.globalScope) {
|
if(info.globalScope) {
|
||||||
info.globalScope.through.forEach(reference => {
|
for(const reference of info.globalScope.through) {
|
||||||
const name = reference.identifier.name;
|
const name = reference.identifier.name;
|
||||||
if(/^__WEBPACK_MODULE_REFERENCE__\d+_([\da-f]+|ns)(_call)?(_strict)?__$/.test(name)) {
|
if(/^__WEBPACK_MODULE_REFERENCE__\d+_([\da-f]+|ns)(_call)?(_strict)?__$/.test(name)) {
|
||||||
for(const s of getSymbolsFromScope(reference.from, info.moduleScope)) {
|
for(const s of getSymbolsFromScope(reference.from, info.moduleScope)) {
|
||||||
|
@ -557,12 +570,12 @@ class ConcatenatedModule extends Module {
|
||||||
} else {
|
} else {
|
||||||
allUsedNames.add(name);
|
allUsedNames.add(name);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
// generate names for symbols
|
// generate names for symbols
|
||||||
modulesWithInfo.forEach(info => {
|
for(const info of modulesWithInfo) {
|
||||||
switch(info.type) {
|
switch(info.type) {
|
||||||
case "concatenated":
|
case "concatenated":
|
||||||
{
|
{
|
||||||
|
@ -570,7 +583,7 @@ class ConcatenatedModule extends Module {
|
||||||
allUsedNames.add(namespaceObjectName);
|
allUsedNames.add(namespaceObjectName);
|
||||||
info.internalNames.set(namespaceObjectName, namespaceObjectName);
|
info.internalNames.set(namespaceObjectName, namespaceObjectName);
|
||||||
info.exportMap.set(true, namespaceObjectName);
|
info.exportMap.set(true, namespaceObjectName);
|
||||||
info.moduleScope.variables.forEach(variable => {
|
for(const variable of info.moduleScope.variables) {
|
||||||
const name = variable.name;
|
const name = variable.name;
|
||||||
if(allUsedNames.has(name)) {
|
if(allUsedNames.has(name)) {
|
||||||
const references = getAllReferences(variable);
|
const references = getAllReferences(variable);
|
||||||
|
@ -593,7 +606,7 @@ class ConcatenatedModule extends Module {
|
||||||
allUsedNames.add(name);
|
allUsedNames.add(name);
|
||||||
info.internalNames.set(name, name);
|
info.internalNames.set(name, name);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "external":
|
case "external":
|
||||||
|
@ -614,12 +627,12 @@ class ConcatenatedModule extends Module {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
// Find and replace referenced to modules
|
// Find and replace referenced to modules
|
||||||
modulesWithInfo.forEach(info => {
|
for(const info of modulesWithInfo) {
|
||||||
if(info.type === "concatenated") {
|
if(info.type === "concatenated") {
|
||||||
info.globalScope.through.forEach(reference => {
|
for(const reference of info.globalScope.through) {
|
||||||
const name = reference.identifier.name;
|
const name = reference.identifier.name;
|
||||||
const match = /^__WEBPACK_MODULE_REFERENCE__(\d+)_([\da-f]+|ns)(_call)?(_strict)?__$/.exec(name);
|
const match = /^__WEBPACK_MODULE_REFERENCE__(\d+)_([\da-f]+|ns)(_call)?(_strict)?__$/.exec(name);
|
||||||
if(match) {
|
if(match) {
|
||||||
|
@ -638,9 +651,9 @@ class ConcatenatedModule extends Module {
|
||||||
const source = info.source;
|
const source = info.source;
|
||||||
source.replace(r[0], r[1] - 1, finalName);
|
source.replace(r[0], r[1] - 1, finalName);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
const result = new ConcatSource();
|
const result = new ConcatSource();
|
||||||
|
|
||||||
|
@ -653,14 +666,14 @@ class ConcatenatedModule extends Module {
|
||||||
}
|
}
|
||||||
|
|
||||||
// define required namespace objects (must be before evaluation modules)
|
// define required namespace objects (must be before evaluation modules)
|
||||||
modulesWithInfo.forEach(info => {
|
for(const info of modulesWithInfo) {
|
||||||
if(info.namespaceObjectSource) {
|
if(info.namespaceObjectSource) {
|
||||||
result.add(info.namespaceObjectSource);
|
result.add(info.namespaceObjectSource);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
// evaluate modules in order
|
// evaluate modules in order
|
||||||
modulesWithInfo.forEach(info => {
|
for(const info of modulesWithInfo) {
|
||||||
switch(info.type) {
|
switch(info.type) {
|
||||||
case "concatenated":
|
case "concatenated":
|
||||||
result.add(`\n// CONCATENATED MODULE: ${info.module.readableIdentifier(requestShortener)}\n`);
|
result.add(`\n// CONCATENATED MODULE: ${info.module.readableIdentifier(requestShortener)}\n`);
|
||||||
|
@ -683,7 +696,7 @@ class ConcatenatedModule extends Module {
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unsupported concatenation entry type ${info.type}`);
|
throw new Error(`Unsupported concatenation entry type ${info.type}`);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -920,7 +933,7 @@ class HarmonyExportImportedSpecifierDependencyConcatenatedTemplate {
|
||||||
if(dep.originModule === this.rootModule) {
|
if(dep.originModule === this.rootModule) {
|
||||||
if(this.modulesMap.get(dep.module)) {
|
if(this.modulesMap.get(dep.module)) {
|
||||||
const exportDefs = this.getExports(dep);
|
const exportDefs = this.getExports(dep);
|
||||||
exportDefs.forEach(def => {
|
for(const def of exportDefs) {
|
||||||
const info = this.modulesMap.get(def.module);
|
const info = this.modulesMap.get(def.module);
|
||||||
const used = dep.originModule.isUsed(def.name);
|
const used = dep.originModule.isUsed(def.name);
|
||||||
if(!used) {
|
if(!used) {
|
||||||
|
@ -937,7 +950,7 @@ class HarmonyExportImportedSpecifierDependencyConcatenatedTemplate {
|
||||||
const exportsName = this.rootModule.exportsArgument;
|
const exportsName = this.rootModule.exportsArgument;
|
||||||
const content = `/* concated harmony reexport */__webpack_require__.d(${exportsName}, ${JSON.stringify(used)}, function() { return ${finalName}; });\n`;
|
const content = `/* concated harmony reexport */__webpack_require__.d(${exportsName}, ${JSON.stringify(used)}, function() { return ${finalName}; });\n`;
|
||||||
source.insert(-1, content);
|
source.insert(-1, content);
|
||||||
});
|
}
|
||||||
} else {
|
} else {
|
||||||
this.originalTemplate.apply(dep, source, runtime, dependencyTemplates);
|
this.originalTemplate.apply(dep, source, runtime, dependencyTemplates);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,25 +9,25 @@ class FlagIncludedChunksPlugin {
|
||||||
apply(compiler) {
|
apply(compiler) {
|
||||||
compiler.hooks.compilation.tap("FlagIncludedChunksPlugin", (compilation) => {
|
compiler.hooks.compilation.tap("FlagIncludedChunksPlugin", (compilation) => {
|
||||||
compilation.hooks.optimizeChunkIds.tap("FlagIncludedChunksPlugin", (chunks) => {
|
compilation.hooks.optimizeChunkIds.tap("FlagIncludedChunksPlugin", (chunks) => {
|
||||||
chunks.forEach((chunkA) => {
|
for(const chunkA of chunks) {
|
||||||
chunks.forEach((chunkB) => {
|
loopB: for(const chunkB of chunks) {
|
||||||
// as we iterate the same iterables twice
|
// as we iterate the same iterables twice
|
||||||
// skip if we find ourselves
|
// skip if we find ourselves
|
||||||
if(chunkA === chunkB) return;
|
if(chunkA === chunkB) continue loopB;
|
||||||
|
|
||||||
// instead of swapping A and B just bail
|
// instead of swapping A and B just bail
|
||||||
// as we loop twice the current A will be B and B then A
|
// as we loop twice the current A will be B and B then A
|
||||||
if(chunkA.getNumberOfModules() < chunkB.getNumberOfModules()) return;
|
if(chunkA.getNumberOfModules() < chunkB.getNumberOfModules()) continue loopB;
|
||||||
|
|
||||||
if(chunkB.getNumberOfModules() === 0) return;
|
if(chunkB.getNumberOfModules() === 0) continue loopB;
|
||||||
|
|
||||||
// is chunkB in chunkA?
|
// is chunkB in chunkA?
|
||||||
for(const m of chunkB.modulesIterable) {
|
for(const m of chunkB.modulesIterable) {
|
||||||
if(!chunkA.containsModule(m)) return;
|
if(!chunkA.containsModule(m)) continue loopB;
|
||||||
}
|
}
|
||||||
chunkA.ids.push(chunkB.id);
|
chunkA.ids.push(chunkB.id);
|
||||||
});
|
}
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,24 +184,28 @@ class ModuleConcatenationPlugin {
|
||||||
const chunks = concatConfiguration.rootModule.getChunks();
|
const chunks = concatConfiguration.rootModule.getChunks();
|
||||||
for(const m of modules) {
|
for(const m of modules) {
|
||||||
usedModules.add(m);
|
usedModules.add(m);
|
||||||
chunks.forEach(chunk => chunk.removeModule(m));
|
for(const chunk of chunks) {
|
||||||
|
chunk.removeModule(m);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
chunks.forEach(chunk => {
|
for(const chunk of chunks) {
|
||||||
chunk.addModule(newModule);
|
chunk.addModule(newModule);
|
||||||
newModule.addChunk(chunk);
|
newModule.addChunk(chunk);
|
||||||
if(chunk.entryModule === concatConfiguration.rootModule)
|
if(chunk.entryModule === concatConfiguration.rootModule)
|
||||||
chunk.entryModule = newModule;
|
chunk.entryModule = newModule;
|
||||||
});
|
}
|
||||||
compilation.modules.push(newModule);
|
compilation.modules.push(newModule);
|
||||||
newModule.reasons.forEach(reason => reason.dependency.module = newModule);
|
for(const reason of newModule.reasons) {
|
||||||
newModule.dependencies.forEach(dep => {
|
reason.dependency.module = newModule;
|
||||||
|
}
|
||||||
|
for(const dep of newModule.dependencies) {
|
||||||
if(dep.module) {
|
if(dep.module) {
|
||||||
dep.module.reasons.forEach(reason => {
|
for(const reason of dep.module.reasons) {
|
||||||
if(reason.dependency === dep)
|
if(reason.dependency === dep)
|
||||||
reason.module = newModule;
|
reason.module = newModule;
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
compilation.modules = compilation.modules.filter(m => !usedModules.has(m));
|
compilation.modules = compilation.modules.filter(m => !usedModules.has(m));
|
||||||
});
|
});
|
||||||
|
|
|
@ -20,7 +20,7 @@ class OccurrenceOrderPlugin {
|
||||||
|
|
||||||
const initialChunkChunkMap = new Map();
|
const initialChunkChunkMap = new Map();
|
||||||
const entryCountMap = new Map();
|
const entryCountMap = new Map();
|
||||||
modules.forEach(m => {
|
for(const m of modules) {
|
||||||
let initial = 0;
|
let initial = 0;
|
||||||
let entry = 0;
|
let entry = 0;
|
||||||
for(const c of m.chunksIterable) {
|
for(const c of m.chunksIterable) {
|
||||||
|
@ -29,7 +29,7 @@ class OccurrenceOrderPlugin {
|
||||||
}
|
}
|
||||||
initialChunkChunkMap.set(m, initial);
|
initialChunkChunkMap.set(m, initial);
|
||||||
entryCountMap.set(m, entry);
|
entryCountMap.set(m, entry);
|
||||||
});
|
}
|
||||||
|
|
||||||
const countOccursInEntry = (sum, r) => {
|
const countOccursInEntry = (sum, r) => {
|
||||||
if(!r.module) return sum;
|
if(!r.module) return sum;
|
||||||
|
@ -45,19 +45,19 @@ class OccurrenceOrderPlugin {
|
||||||
};
|
};
|
||||||
|
|
||||||
if(preferEntry) {
|
if(preferEntry) {
|
||||||
modules.forEach(m => {
|
for(const m of modules) {
|
||||||
const result = m.reasons.reduce(countOccursInEntry, 0) + initialChunkChunkMap.get(m) + entryCountMap.get(m);
|
const result = m.reasons.reduce(countOccursInEntry, 0) + initialChunkChunkMap.get(m) + entryCountMap.get(m);
|
||||||
occursInInitialChunksMap.set(m, result);
|
occursInInitialChunksMap.set(m, result);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const originalOrder = new Map();
|
const originalOrder = new Map();
|
||||||
let i = 0;
|
let i = 0;
|
||||||
modules.forEach(m => {
|
for(const m of modules) {
|
||||||
const result = m.reasons.reduce(countOccurs, 0) + m.getNumberOfChunks() + entryCountMap.get(m);
|
const result = m.reasons.reduce(countOccurs, 0) + m.getNumberOfChunks() + entryCountMap.get(m);
|
||||||
occursInAllChunksMap.set(m, result);
|
occursInAllChunksMap.set(m, result);
|
||||||
originalOrder.set(m, i++);
|
originalOrder.set(m, i++);
|
||||||
});
|
}
|
||||||
|
|
||||||
modules.sort((a, b) => {
|
modules.sort((a, b) => {
|
||||||
if(preferEntry) {
|
if(preferEntry) {
|
||||||
|
@ -80,7 +80,7 @@ class OccurrenceOrderPlugin {
|
||||||
const originalOrder = new Map();
|
const originalOrder = new Map();
|
||||||
|
|
||||||
let i = 0;
|
let i = 0;
|
||||||
chunks.forEach(c => {
|
for(const c of chunks) {
|
||||||
let occurs = 0;
|
let occurs = 0;
|
||||||
for(const chunkGroup of c.groupsIterable) {
|
for(const chunkGroup of c.groupsIterable) {
|
||||||
for(const parent of chunkGroup.parentsIterable) {
|
for(const parent of chunkGroup.parentsIterable) {
|
||||||
|
@ -90,19 +90,15 @@ class OccurrenceOrderPlugin {
|
||||||
}
|
}
|
||||||
occursInInitialChunksMap.set(c, occurs);
|
occursInInitialChunksMap.set(c, occurs);
|
||||||
originalOrder.set(c, i++);
|
originalOrder.set(c, i++);
|
||||||
});
|
}
|
||||||
|
|
||||||
const occurs = c => {
|
|
||||||
return c.getNumberOfGroups();
|
|
||||||
};
|
|
||||||
|
|
||||||
chunks.sort((a, b) => {
|
chunks.sort((a, b) => {
|
||||||
const aEntryOccurs = occursInInitialChunksMap.get(a);
|
const aEntryOccurs = occursInInitialChunksMap.get(a);
|
||||||
const bEntryOccurs = occursInInitialChunksMap.get(b);
|
const bEntryOccurs = occursInInitialChunksMap.get(b);
|
||||||
if(aEntryOccurs > bEntryOccurs) return -1;
|
if(aEntryOccurs > bEntryOccurs) return -1;
|
||||||
if(aEntryOccurs < bEntryOccurs) return 1;
|
if(aEntryOccurs < bEntryOccurs) return 1;
|
||||||
const aOccurs = occurs(a);
|
const aOccurs = a.getNumberOfGroups();
|
||||||
const bOccurs = occurs(b);
|
const bOccurs = b.getNumberOfGroups();
|
||||||
if(aOccurs > bOccurs) return -1;
|
if(aOccurs > bOccurs) return -1;
|
||||||
if(aOccurs < bOccurs) return 1;
|
if(aOccurs < bOccurs) return 1;
|
||||||
const orgA = originalOrder.get(a);
|
const orgA = originalOrder.get(a);
|
||||||
|
|
|
@ -34,20 +34,21 @@ module.exports = class SizeLimitsPlugin {
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
const assetsOverSizeLimit = [];
|
const assetsOverSizeLimit = [];
|
||||||
Object.keys(compilation.assets)
|
for(const assetName of Object.keys(compilation.assets)) {
|
||||||
.filter(assetFilter)
|
if(!assetFilter(assetName)) {
|
||||||
.forEach(assetName => {
|
continue;
|
||||||
const asset = compilation.assets[assetName];
|
}
|
||||||
const size = asset.size();
|
|
||||||
|
|
||||||
if(size > assetSizeLimit) {
|
const asset = compilation.assets[assetName];
|
||||||
assetsOverSizeLimit.push({
|
const size = asset.size();
|
||||||
name: assetName,
|
if(size > assetSizeLimit) {
|
||||||
size: size,
|
assetsOverSizeLimit.push({
|
||||||
});
|
name: assetName,
|
||||||
asset.isOverSizeLimit = true;
|
size: size,
|
||||||
}
|
});
|
||||||
});
|
asset.isOverSizeLimit = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const entrypointsOverLimit = [];
|
const entrypointsOverLimit = [];
|
||||||
for(const pair of compilation.entrypoints) {
|
for(const pair of compilation.entrypoints) {
|
||||||
|
|
|
@ -41,7 +41,7 @@ const validateObject = (schema, options) => {
|
||||||
|
|
||||||
const filterErrors = errors => {
|
const filterErrors = errors => {
|
||||||
let newErrors = [];
|
let newErrors = [];
|
||||||
errors.forEach((err) => {
|
for(const err of errors) {
|
||||||
const dataPath = err.dataPath;
|
const dataPath = err.dataPath;
|
||||||
let children = [];
|
let children = [];
|
||||||
newErrors = newErrors.filter((oldError) => {
|
newErrors = newErrors.filter((oldError) => {
|
||||||
|
@ -59,7 +59,7 @@ const filterErrors = errors => {
|
||||||
err.children = children;
|
err.children = children;
|
||||||
}
|
}
|
||||||
newErrors.push(err);
|
newErrors.push(err);
|
||||||
});
|
}
|
||||||
|
|
||||||
return newErrors;
|
return newErrors;
|
||||||
};
|
};
|
||||||
|
|
|
@ -31,10 +31,10 @@ class FetchCompileWasmMainTemplatePlugin {
|
||||||
hash: `" + ${JSON.stringify(chunkModuleMaps.hash)}[wasmModuleId] + "`,
|
hash: `" + ${JSON.stringify(chunkModuleMaps.hash)}[wasmModuleId] + "`,
|
||||||
hashWithLength(length) {
|
hashWithLength(length) {
|
||||||
const shortChunkHashMap = Object.create(null);
|
const shortChunkHashMap = Object.create(null);
|
||||||
Object.keys(chunkModuleMaps.hash).forEach(wasmModuleId => {
|
for(const wasmModuleId of Object.keys(chunkModuleMaps.hash)) {
|
||||||
if(typeof chunkModuleMaps.hash[wasmModuleId] === "string")
|
if(typeof chunkModuleMaps.hash[wasmModuleId] === "string")
|
||||||
shortChunkHashMap[wasmModuleId] = chunkModuleMaps.hash[wasmModuleId].substr(0, length);
|
shortChunkHashMap[wasmModuleId] = chunkModuleMaps.hash[wasmModuleId].substr(0, length);
|
||||||
});
|
}
|
||||||
return `" + ${JSON.stringify(shortChunkHashMap)}[wasmModuleId] + "`;
|
return `" + ${JSON.stringify(shortChunkHashMap)}[wasmModuleId] + "`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,10 +65,10 @@ class JsonpMainTemplatePlugin {
|
||||||
hash: `" + ${JSON.stringify(chunkMaps.hash)}[chunkId] + "`,
|
hash: `" + ${JSON.stringify(chunkMaps.hash)}[chunkId] + "`,
|
||||||
hashWithLength(length) {
|
hashWithLength(length) {
|
||||||
const shortChunkHashMap = Object.create(null);
|
const shortChunkHashMap = Object.create(null);
|
||||||
Object.keys(chunkMaps.hash).forEach(chunkId => {
|
for(const chunkId of Object.keys(chunkMaps.hash)) {
|
||||||
if(typeof chunkMaps.hash[chunkId] === "string")
|
if(typeof chunkMaps.hash[chunkId] === "string")
|
||||||
shortChunkHashMap[chunkId] = chunkMaps.hash[chunkId].substr(0, length);
|
shortChunkHashMap[chunkId] = chunkMaps.hash[chunkId].substr(0, length);
|
||||||
});
|
}
|
||||||
return `" + ${JSON.stringify(shortChunkHashMap)}[chunkId] + "`;
|
return `" + ${JSON.stringify(shortChunkHashMap)}[chunkId] + "`;
|
||||||
},
|
},
|
||||||
name: `" + (${JSON.stringify(chunkMaps.name)}[chunkId]||chunkId) + "`
|
name: `" + (${JSON.stringify(chunkMaps.name)}[chunkId]||chunkId) + "`
|
||||||
|
|
|
@ -28,7 +28,9 @@ const webpack = (options, callback) => {
|
||||||
compiler.options = options;
|
compiler.options = options;
|
||||||
new NodeEnvironmentPlugin().apply(compiler);
|
new NodeEnvironmentPlugin().apply(compiler);
|
||||||
if(options.plugins && Array.isArray(options.plugins)) {
|
if(options.plugins && Array.isArray(options.plugins)) {
|
||||||
options.plugins.forEach(plugin => plugin.apply(compiler));
|
for(const plugin of options.plugins) {
|
||||||
|
plugin.apply(compiler);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
compiler.hooks.environment.call();
|
compiler.hooks.environment.call();
|
||||||
compiler.hooks.afterEnvironment.call();
|
compiler.hooks.afterEnvironment.call();
|
||||||
|
@ -59,13 +61,13 @@ webpack.validateSchema = validateSchema;
|
||||||
webpack.WebpackOptionsValidationError = WebpackOptionsValidationError;
|
webpack.WebpackOptionsValidationError = WebpackOptionsValidationError;
|
||||||
|
|
||||||
const exportPlugins = (obj, mappings) => {
|
const exportPlugins = (obj, mappings) => {
|
||||||
Object.keys(mappings).forEach(name => {
|
for(const name of Object.keys(mappings)) {
|
||||||
Object.defineProperty(obj, name, {
|
Object.defineProperty(obj, name, {
|
||||||
configurable: false,
|
configurable: false,
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
get: mappings[name]
|
get: mappings[name]
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exportPlugins(exports, {
|
exportPlugins(exports, {
|
||||||
|
|
Loading…
Reference in New Issue