Skip to content

Commit

Permalink
Merge pull request #6640 from clarkdo/module-assets
Browse files Browse the repository at this point in the history
fix: module assets is in buildInfo
  • Loading branch information
sokra committed Mar 5, 2018
2 parents 01a5224 + 23208a3 commit ae2ae4e
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/Stats.js
Expand Up @@ -136,6 +136,10 @@ class Stats {
options.nestedModules,
true
);
const showModuleAssets = optionOrLocalFallback(
options.moduleAssets,
!forToString
);
const showDepth = optionOrLocalFallback(options.depth, !forToString);
const showCachedModules = optionOrLocalFallback(options.cached, true);
const showCachedAssets = optionOrLocalFallback(options.cachedAssets, true);
Expand Down Expand Up @@ -417,7 +421,6 @@ class Stats {
optional: module.optional,
prefetched: module.prefetched,
chunks: Array.from(module.chunksIterable, chunk => chunk.id),
assets: Object.keys(module.assets || {}),
issuer: module.issuer && module.issuer.identifier(),
issuerId: module.issuer && module.issuer.id,
issuerName:
Expand All @@ -435,6 +438,9 @@ class Stats {
errors: module.errors ? module.errors.length : 0,
warnings: module.warnings ? module.warnings.length : 0
};
if (showModuleAssets) {
obj.assets = Object.keys(module.buildInfo.assets || {});
}
if (showReasons) {
obj.reasons = module.reasons
.map(reason => {
Expand Down Expand Up @@ -867,6 +873,13 @@ class Stats {
if (module.built) {
colors.green(" [built]");
}
if (module.assets && module.assets.length) {
colors.magenta(
` [${module.assets.length} asset${
module.assets.length === 1 ? "" : "s"
}]`
);
}
if (module.prefetched) {
colors.magenta(" [prefetched]");
}
Expand Down
4 changes: 4 additions & 0 deletions schemas/WebpackOptions.json
Expand Up @@ -1767,6 +1767,10 @@
"type": "boolean",
"description": "add information about modules nested in other modules (like with module concatenation)"
},
"moduleAssets": {
"type": "boolean",
"description": "add information about assets inside modules"
},
"children": {
"type": "boolean",
"description": "add children information"
Expand Down
12 changes: 12 additions & 0 deletions test/statsCases/module-assets/expected.txt
@@ -0,0 +1,12 @@
Hash: d71bd16b0b20f34e994a
Time: Xms
Built at: Thu Jan 01 1970 00:00:00 GMT
Entrypoint main = main.js
chunk {0} 0.js 68 bytes <{1}> [rendered]
[0] ./node_modules/a/1.png 51 bytes {0} [built] [1 asset]
[1] ./node_modules/a/index.js 17 bytes {0} [built]
chunk {1} main.js (main) 12 bytes >{0}< [entry] [rendered]
[2] ./index.js 12 bytes {1} [built]
[0] ./node_modules/a/1.png 51 bytes {0} [built] [1 asset]
[1] ./node_modules/a/index.js 17 bytes {0} [built]
[2] ./index.js 12 bytes {1} [built]
1 change: 1 addition & 0 deletions test/statsCases/module-assets/index.js
@@ -0,0 +1 @@
import('a')
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/statsCases/module-assets/node_modules/a/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions test/statsCases/module-assets/webpack.config.js
@@ -0,0 +1,26 @@
module.exports = {
mode: "production",
entry: "./index",
stats: {
assets: false,
chunks: true,
chunkModules: true,
modules: true,
moduleAssets: true
},
module: {
rules: [
{
test: /\.png$/,
use: [
{
loader: "file-loader",
options: {
name: "[name].[ext]"
}
}
]
}
]
}
};

0 comments on commit ae2ae4e

Please sign in to comment.