mirror of https://github.com/webpack/webpack.git
Merge pull request #7812 from webpack/feature/orphan_modules
Hide orphan modules in Stats
This commit is contained in:
commit
d12e283ba1
34
lib/Stats.js
34
lib/Stats.js
|
|
@ -173,6 +173,10 @@ class Stats {
|
||||||
options.nestedModules,
|
options.nestedModules,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
const showOrphanModules = optionOrLocalFallback(
|
||||||
|
options.orphanModules,
|
||||||
|
false
|
||||||
|
);
|
||||||
const showModuleAssets = optionOrLocalFallback(
|
const showModuleAssets = optionOrLocalFallback(
|
||||||
options.moduleAssets,
|
options.moduleAssets,
|
||||||
!forToString
|
!forToString
|
||||||
|
|
@ -225,16 +229,22 @@ class Stats {
|
||||||
!forToString
|
!forToString
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!showOrphanModules) {
|
||||||
|
excludeModules.push((ident, module, type) => {
|
||||||
|
return module.getNumberOfChunks() === 0 && type !== "nested";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (!showCachedModules) {
|
if (!showCachedModules) {
|
||||||
excludeModules.push((ident, module) => !module.built);
|
excludeModules.push((ident, module) => !module.built);
|
||||||
}
|
}
|
||||||
|
|
||||||
const createModuleFilter = () => {
|
const createModuleFilter = type => {
|
||||||
let i = 0;
|
let i = 0;
|
||||||
return module => {
|
return module => {
|
||||||
if (excludeModules.length > 0) {
|
if (excludeModules.length > 0) {
|
||||||
const ident = requestShortener.shorten(module.resource);
|
const ident = requestShortener.shorten(module.resource);
|
||||||
const excluded = excludeModules.some(fn => fn(ident, module));
|
const excluded = excludeModules.some(fn => fn(ident, module, type));
|
||||||
if (excluded) return false;
|
if (excluded) return false;
|
||||||
}
|
}
|
||||||
const result = i < maxModules;
|
const result = i < maxModules;
|
||||||
|
|
@ -492,7 +502,7 @@ class Stats {
|
||||||
obj.namedChunkGroups = fnChunkGroup(compilation.namedChunkGroups);
|
obj.namedChunkGroups = fnChunkGroup(compilation.namedChunkGroups);
|
||||||
}
|
}
|
||||||
|
|
||||||
const fnModule = module => {
|
const fnModule = (module, nested) => {
|
||||||
const path = [];
|
const path = [];
|
||||||
const issuer = module.getIssuer(moduleGraph);
|
const issuer = module.getIssuer(moduleGraph);
|
||||||
let current = issuer;
|
let current = issuer;
|
||||||
|
|
@ -529,6 +539,9 @@ class Stats {
|
||||||
errors: module.errors ? module.errors.length : 0,
|
errors: module.errors ? module.errors.length : 0,
|
||||||
warnings: module.warnings ? module.warnings.length : 0
|
warnings: module.warnings ? module.warnings.length : 0
|
||||||
};
|
};
|
||||||
|
if (showOrphanModules && !nested) {
|
||||||
|
obj.orphan = module.getNumberOfChunks() === 0;
|
||||||
|
}
|
||||||
if (showModuleAssets) {
|
if (showModuleAssets) {
|
||||||
obj.assets = Object.keys(module.buildInfo.assets || {});
|
obj.assets = Object.keys(module.buildInfo.assets || {});
|
||||||
}
|
}
|
||||||
|
|
@ -612,8 +625,8 @@ class Stats {
|
||||||
const modules = module.modules;
|
const modules = module.modules;
|
||||||
obj.modules = modules
|
obj.modules = modules
|
||||||
.sort(sortByField("depth"))
|
.sort(sortByField("depth"))
|
||||||
.filter(createModuleFilter())
|
.filter(createModuleFilter("nested"))
|
||||||
.map(fnModule);
|
.map(m => fnModule(m, true));
|
||||||
obj.filteredModules = modules.length - obj.modules.length;
|
obj.filteredModules = modules.length - obj.modules.length;
|
||||||
obj.modules.sort(sortByField(sortModules));
|
obj.modules.sort(sortByField(sortModules));
|
||||||
}
|
}
|
||||||
|
|
@ -664,8 +677,8 @@ class Stats {
|
||||||
obj.modules = chunk
|
obj.modules = chunk
|
||||||
.getModules()
|
.getModules()
|
||||||
.sort(sortByField("depth"))
|
.sort(sortByField("depth"))
|
||||||
.filter(createModuleFilter())
|
.filter(createModuleFilter("chunk"))
|
||||||
.map(fnModule);
|
.map(m => fnModule(m));
|
||||||
obj.filteredModules = chunk.getNumberOfModules() - obj.modules.length;
|
obj.filteredModules = chunk.getNumberOfModules() - obj.modules.length;
|
||||||
obj.modules.sort(sortByField(sortModules));
|
obj.modules.sort(sortByField(sortModules));
|
||||||
}
|
}
|
||||||
|
|
@ -713,8 +726,8 @@ class Stats {
|
||||||
obj.modules = compilation.modules
|
obj.modules = compilation.modules
|
||||||
.slice()
|
.slice()
|
||||||
.sort(sortByField("depth"))
|
.sort(sortByField("depth"))
|
||||||
.filter(createModuleFilter())
|
.filter(createModuleFilter("module"))
|
||||||
.map(fnModule);
|
.map(m => fnModule(m));
|
||||||
obj.filteredModules = compilation.modules.length - obj.modules.length;
|
obj.filteredModules = compilation.modules.length - obj.modules.length;
|
||||||
obj.modules.sort(sortByField(sortModules));
|
obj.modules.sort(sortByField(sortModules));
|
||||||
}
|
}
|
||||||
|
|
@ -1036,6 +1049,9 @@ class Stats {
|
||||||
if (module.cacheable === false) {
|
if (module.cacheable === false) {
|
||||||
colors.red(" [not cacheable]");
|
colors.red(" [not cacheable]");
|
||||||
}
|
}
|
||||||
|
if (module.orphan) {
|
||||||
|
colors.yellow(" [orphan]");
|
||||||
|
}
|
||||||
if (module.optional) {
|
if (module.optional) {
|
||||||
colors.yellow(" [optional]");
|
colors.yellow(" [optional]");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1844,6 +1844,10 @@
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"description": "add built modules information"
|
"description": "add built modules information"
|
||||||
},
|
},
|
||||||
|
"orphanModules": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "add information about orphan modules"
|
||||||
|
},
|
||||||
"nestedModules": {
|
"nestedModules": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"description": "add information about modules nested in other modules (like with module concatenation)"
|
"description": "add information about modules nested in other modules (like with module concatenation)"
|
||||||
|
|
@ -1858,7 +1862,7 @@
|
||||||
},
|
},
|
||||||
"cached": {
|
"cached": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"description": "add also information about cached (not built) modules"
|
"description": "add information about cached (not built) modules"
|
||||||
},
|
},
|
||||||
"cachedAssets": {
|
"cachedAssets": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
|
|
|
||||||
|
|
@ -679,15 +679,15 @@ exports[`StatsTestCases should print correct stats for concat-and-sideeffects 1`
|
||||||
| ./index.js 46 bytes [built]
|
| ./index.js 46 bytes [built]
|
||||||
| ./node_modules/pmodule/a.js 49 bytes [built]
|
| ./node_modules/pmodule/a.js 49 bytes [built]
|
||||||
| ./node_modules/pmodule/aa.js 24 bytes [built]
|
| ./node_modules/pmodule/aa.js 24 bytes [built]
|
||||||
./node_modules/pmodule/index.js 63 bytes [built]
|
./node_modules/pmodule/index.js 63 bytes [orphan] [built]
|
||||||
ModuleConcatenation bailout: Module is not in any chunk
|
ModuleConcatenation bailout: Module is not in any chunk
|
||||||
./node_modules/pmodule/b.js 49 bytes [built]
|
./node_modules/pmodule/b.js 49 bytes [orphan] [built]
|
||||||
ModuleConcatenation bailout: Module is not in any chunk
|
ModuleConcatenation bailout: Module is not in any chunk
|
||||||
./node_modules/pmodule/c.js 49 bytes [built]
|
./node_modules/pmodule/c.js 49 bytes [orphan] [built]
|
||||||
ModuleConcatenation bailout: Module is not in any chunk
|
ModuleConcatenation bailout: Module is not in any chunk
|
||||||
./node_modules/pmodule/bb.js 24 bytes [built]
|
./node_modules/pmodule/bb.js 24 bytes [orphan] [built]
|
||||||
ModuleConcatenation bailout: Module is not in any chunk
|
ModuleConcatenation bailout: Module is not in any chunk
|
||||||
./node_modules/pmodule/cc.js 24 bytes [built]
|
./node_modules/pmodule/cc.js 24 bytes [orphan] [built]
|
||||||
ModuleConcatenation bailout: Module is not in any chunk"
|
ModuleConcatenation bailout: Module is not in any chunk"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|
@ -1097,7 +1097,7 @@ entry.js 8.46 KiB 0 [emitted] entry
|
||||||
Entrypoint entry = entry.js
|
Entrypoint entry = entry.js
|
||||||
[0] ./entry.js 120 bytes {0} [built]
|
[0] ./entry.js 120 bytes {0} [built]
|
||||||
[1] ./modules/b.js 22 bytes {1} [built]
|
[1] ./modules/b.js 22 bytes {1} [built]
|
||||||
./modules/a.js 37 bytes [built]"
|
+ 1 hidden module"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`StatsTestCases should print correct stats for import-with-invalid-options-comments 1`] = `
|
exports[`StatsTestCases should print correct stats for import-with-invalid-options-comments 1`] = `
|
||||||
|
|
@ -2247,20 +2247,20 @@ Entrypoint main = main.js
|
||||||
| ./components/src/CompAB/CompB.js 77 bytes [built]
|
| ./components/src/CompAB/CompB.js 77 bytes [built]
|
||||||
| [only some exports used: default]
|
| [only some exports used: default]
|
||||||
| harmony import specifier ./components ./main.js 4:15-20 (skipped side-effect-free modules)
|
| harmony import specifier ./components ./main.js 4:15-20 (skipped side-effect-free modules)
|
||||||
./components/src/index.js 84 bytes [built]
|
./components/src/index.js 84 bytes [orphan] [built]
|
||||||
[module unused]
|
[module unused]
|
||||||
harmony side effect evaluation ./components [2] ./foo.js 1:0-37
|
harmony side effect evaluation ./components [2] ./foo.js 1:0-37
|
||||||
harmony side effect evaluation ./components [3] ./main.js + 1 modules 1:0-44
|
harmony side effect evaluation ./components [3] ./main.js + 1 modules 1:0-44
|
||||||
./components/src/CompAB/index.js 87 bytes [built]
|
./components/src/CompAB/index.js 87 bytes [orphan] [built]
|
||||||
[module unused]
|
[module unused]
|
||||||
harmony side effect evaluation ./CompAB ./components/src/index.js 1:0-40
|
harmony side effect evaluation ./CompAB ./components/src/index.js 1:0-40
|
||||||
harmony export imported specifier ./CompAB ./components/src/index.js 1:0-40
|
harmony export imported specifier ./CompAB ./components/src/index.js 1:0-40
|
||||||
harmony export imported specifier ./CompAB ./components/src/index.js 1:0-40
|
harmony export imported specifier ./CompAB ./components/src/index.js 1:0-40
|
||||||
./components/src/CompC/index.js 34 bytes [built]
|
./components/src/CompC/index.js 34 bytes [orphan] [built]
|
||||||
[module unused]
|
[module unused]
|
||||||
harmony side effect evaluation ./CompC ./components/src/index.js 2:0-43
|
harmony side effect evaluation ./CompC ./components/src/index.js 2:0-43
|
||||||
harmony export imported specifier ./CompC ./components/src/index.js 2:0-43
|
harmony export imported specifier ./CompC ./components/src/index.js 2:0-43
|
||||||
./components/src/CompC/CompC.js 33 bytes [built]
|
./components/src/CompC/CompC.js 33 bytes [orphan] [built]
|
||||||
[module unused]
|
[module unused]
|
||||||
harmony side effect evaluation ./CompC ./components/src/CompC/index.js 1:0-34
|
harmony side effect evaluation ./CompC ./components/src/CompC/index.js 1:0-34
|
||||||
harmony export imported specifier ./CompC ./components/src/CompC/index.js 1:0-34"
|
harmony export imported specifier ./CompC ./components/src/CompC/index.js 1:0-34"
|
||||||
|
|
@ -2285,11 +2285,11 @@ Entrypoint main = main.js
|
||||||
| ./node_modules/pmodule/c.js 28 bytes [built]
|
| ./node_modules/pmodule/c.js 28 bytes [built]
|
||||||
| [only some exports used: z]
|
| [only some exports used: z]
|
||||||
| harmony import specifier pmodule ./index.js 3:17-18 (skipped side-effect-free modules)
|
| harmony import specifier pmodule ./index.js 3:17-18 (skipped side-effect-free modules)
|
||||||
./node_modules/pmodule/a.js 60 bytes [built]
|
./node_modules/pmodule/a.js 60 bytes [orphan] [built]
|
||||||
[module unused]
|
[module unused]
|
||||||
harmony side effect evaluation ./a [0] ./index.js + 2 modules 1:0-20
|
harmony side effect evaluation ./a [0] ./index.js + 2 modules 1:0-20
|
||||||
harmony export imported specifier ./a [0] ./index.js + 2 modules 1:0-20
|
harmony export imported specifier ./a [0] ./index.js + 2 modules 1:0-20
|
||||||
./node_modules/pmodule/b.js 69 bytes [built]
|
./node_modules/pmodule/b.js 69 bytes [orphan] [built]
|
||||||
[module unused]
|
[module unused]
|
||||||
harmony side effect evaluation ./b [0] ./index.js + 2 modules 2:0-30
|
harmony side effect evaluation ./b [0] ./index.js + 2 modules 2:0-30
|
||||||
harmony export imported specifier ./b [0] ./index.js + 2 modules 2:0-30
|
harmony export imported specifier ./b [0] ./index.js + 2 modules 2:0-30
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ module.exports = {
|
||||||
all: false,
|
all: false,
|
||||||
modules: true,
|
modules: true,
|
||||||
nestedModules: true,
|
nestedModules: true,
|
||||||
|
orphanModules: true,
|
||||||
optimizationBailout: true
|
optimizationBailout: true
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ module.exports = {
|
||||||
externals: ["external"],
|
externals: ["external"],
|
||||||
stats: {
|
stats: {
|
||||||
assets: false,
|
assets: false,
|
||||||
|
orphanModules: true,
|
||||||
optimizationBailout: true
|
optimizationBailout: true
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@ module.exports = [
|
||||||
},
|
},
|
||||||
stats: {
|
stats: {
|
||||||
assets: false,
|
assets: false,
|
||||||
|
orphanModules: true,
|
||||||
optimizationBailout: true
|
optimizationBailout: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ module.exports = {
|
||||||
concatenateModules: true
|
concatenateModules: true
|
||||||
},
|
},
|
||||||
stats: {
|
stats: {
|
||||||
|
orphanModules: true,
|
||||||
nestedModules: true,
|
nestedModules: true,
|
||||||
usedExports: true,
|
usedExports: true,
|
||||||
reasons: true
|
reasons: true
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ module.exports = {
|
||||||
optimization: { moduleIds: "natural", chunkIds: "natural" },
|
optimization: { moduleIds: "natural", chunkIds: "natural" },
|
||||||
entry: "./index",
|
entry: "./index",
|
||||||
stats: {
|
stats: {
|
||||||
|
orphanModules: true,
|
||||||
nestedModules: true,
|
nestedModules: true,
|
||||||
usedExports: true,
|
usedExports: true,
|
||||||
reasons: true
|
reasons: true
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue