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,
|
||||
true
|
||||
);
|
||||
const showOrphanModules = optionOrLocalFallback(
|
||||
options.orphanModules,
|
||||
false
|
||||
);
|
||||
const showModuleAssets = optionOrLocalFallback(
|
||||
options.moduleAssets,
|
||||
!forToString
|
||||
|
|
@ -225,16 +229,22 @@ class Stats {
|
|||
!forToString
|
||||
);
|
||||
|
||||
if (!showOrphanModules) {
|
||||
excludeModules.push((ident, module, type) => {
|
||||
return module.getNumberOfChunks() === 0 && type !== "nested";
|
||||
});
|
||||
}
|
||||
|
||||
if (!showCachedModules) {
|
||||
excludeModules.push((ident, module) => !module.built);
|
||||
}
|
||||
|
||||
const createModuleFilter = () => {
|
||||
const createModuleFilter = type => {
|
||||
let i = 0;
|
||||
return module => {
|
||||
if (excludeModules.length > 0) {
|
||||
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;
|
||||
}
|
||||
const result = i < maxModules;
|
||||
|
|
@ -492,7 +502,7 @@ class Stats {
|
|||
obj.namedChunkGroups = fnChunkGroup(compilation.namedChunkGroups);
|
||||
}
|
||||
|
||||
const fnModule = module => {
|
||||
const fnModule = (module, nested) => {
|
||||
const path = [];
|
||||
const issuer = module.getIssuer(moduleGraph);
|
||||
let current = issuer;
|
||||
|
|
@ -529,6 +539,9 @@ class Stats {
|
|||
errors: module.errors ? module.errors.length : 0,
|
||||
warnings: module.warnings ? module.warnings.length : 0
|
||||
};
|
||||
if (showOrphanModules && !nested) {
|
||||
obj.orphan = module.getNumberOfChunks() === 0;
|
||||
}
|
||||
if (showModuleAssets) {
|
||||
obj.assets = Object.keys(module.buildInfo.assets || {});
|
||||
}
|
||||
|
|
@ -612,8 +625,8 @@ class Stats {
|
|||
const modules = module.modules;
|
||||
obj.modules = modules
|
||||
.sort(sortByField("depth"))
|
||||
.filter(createModuleFilter())
|
||||
.map(fnModule);
|
||||
.filter(createModuleFilter("nested"))
|
||||
.map(m => fnModule(m, true));
|
||||
obj.filteredModules = modules.length - obj.modules.length;
|
||||
obj.modules.sort(sortByField(sortModules));
|
||||
}
|
||||
|
|
@ -664,8 +677,8 @@ class Stats {
|
|||
obj.modules = chunk
|
||||
.getModules()
|
||||
.sort(sortByField("depth"))
|
||||
.filter(createModuleFilter())
|
||||
.map(fnModule);
|
||||
.filter(createModuleFilter("chunk"))
|
||||
.map(m => fnModule(m));
|
||||
obj.filteredModules = chunk.getNumberOfModules() - obj.modules.length;
|
||||
obj.modules.sort(sortByField(sortModules));
|
||||
}
|
||||
|
|
@ -713,8 +726,8 @@ class Stats {
|
|||
obj.modules = compilation.modules
|
||||
.slice()
|
||||
.sort(sortByField("depth"))
|
||||
.filter(createModuleFilter())
|
||||
.map(fnModule);
|
||||
.filter(createModuleFilter("module"))
|
||||
.map(m => fnModule(m));
|
||||
obj.filteredModules = compilation.modules.length - obj.modules.length;
|
||||
obj.modules.sort(sortByField(sortModules));
|
||||
}
|
||||
|
|
@ -1036,6 +1049,9 @@ class Stats {
|
|||
if (module.cacheable === false) {
|
||||
colors.red(" [not cacheable]");
|
||||
}
|
||||
if (module.orphan) {
|
||||
colors.yellow(" [orphan]");
|
||||
}
|
||||
if (module.optional) {
|
||||
colors.yellow(" [optional]");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1844,6 +1844,10 @@
|
|||
"type": "boolean",
|
||||
"description": "add built modules information"
|
||||
},
|
||||
"orphanModules": {
|
||||
"type": "boolean",
|
||||
"description": "add information about orphan modules"
|
||||
},
|
||||
"nestedModules": {
|
||||
"type": "boolean",
|
||||
"description": "add information about modules nested in other modules (like with module concatenation)"
|
||||
|
|
@ -1858,7 +1862,7 @@
|
|||
},
|
||||
"cached": {
|
||||
"type": "boolean",
|
||||
"description": "add also information about cached (not built) modules"
|
||||
"description": "add information about cached (not built) modules"
|
||||
},
|
||||
"cachedAssets": {
|
||||
"type": "boolean",
|
||||
|
|
|
|||
|
|
@ -679,15 +679,15 @@ exports[`StatsTestCases should print correct stats for concat-and-sideeffects 1`
|
|||
| ./index.js 46 bytes [built]
|
||||
| ./node_modules/pmodule/a.js 49 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
|
||||
./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
|
||||
./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
|
||||
./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
|
||||
./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"
|
||||
`;
|
||||
|
||||
|
|
@ -1097,7 +1097,7 @@ entry.js 8.46 KiB 0 [emitted] entry
|
|||
Entrypoint entry = entry.js
|
||||
[0] ./entry.js 120 bytes {0} [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`] = `
|
||||
|
|
@ -2247,20 +2247,20 @@ Entrypoint main = main.js
|
|||
| ./components/src/CompAB/CompB.js 77 bytes [built]
|
||||
| [only some exports used: default]
|
||||
| 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]
|
||||
harmony side effect evaluation ./components [2] ./foo.js 1:0-37
|
||||
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]
|
||||
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
|
||||
./components/src/CompC/index.js 34 bytes [built]
|
||||
./components/src/CompC/index.js 34 bytes [orphan] [built]
|
||||
[module unused]
|
||||
harmony side effect evaluation ./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]
|
||||
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"
|
||||
|
|
@ -2285,11 +2285,11 @@ Entrypoint main = main.js
|
|||
| ./node_modules/pmodule/c.js 28 bytes [built]
|
||||
| [only some exports used: z]
|
||||
| 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]
|
||||
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
|
||||
./node_modules/pmodule/b.js 69 bytes [built]
|
||||
./node_modules/pmodule/b.js 69 bytes [orphan] [built]
|
||||
[module unused]
|
||||
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
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ module.exports = {
|
|||
all: false,
|
||||
modules: true,
|
||||
nestedModules: true,
|
||||
orphanModules: true,
|
||||
optimizationBailout: true
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ module.exports = {
|
|||
externals: ["external"],
|
||||
stats: {
|
||||
assets: false,
|
||||
orphanModules: true,
|
||||
optimizationBailout: true
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ module.exports = [
|
|||
},
|
||||
stats: {
|
||||
assets: false,
|
||||
orphanModules: true,
|
||||
optimizationBailout: true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ module.exports = {
|
|||
concatenateModules: true
|
||||
},
|
||||
stats: {
|
||||
orphanModules: true,
|
||||
nestedModules: true,
|
||||
usedExports: true,
|
||||
reasons: true
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ module.exports = {
|
|||
optimization: { moduleIds: "natural", chunkIds: "natural" },
|
||||
entry: "./index",
|
||||
stats: {
|
||||
orphanModules: true,
|
||||
nestedModules: true,
|
||||
usedExports: true,
|
||||
reasons: true
|
||||
|
|
|
|||
Loading…
Reference in New Issue