diff --git a/lib/stats/DefaultStatsPrinterPlugin.js b/lib/stats/DefaultStatsPrinterPlugin.js
index 71c35e1fe30..e1eb6ca47cc 100644
--- a/lib/stats/DefaultStatsPrinterPlugin.js
+++ b/lib/stats/DefaultStatsPrinterPlugin.js
@@ -10,6 +10,7 @@
/** @typedef {import("./StatsPrinter").StatsPrinterContext} StatsPrinterContext */
const DATA_URI_CONTENT_LENGTH = 16;
+const MAX_MODULE_IDENTIFIER_LENGTH = 80;
const plural = (n, singular, plural) => (n === 1 ? singular : plural);
@@ -42,6 +43,19 @@ const getResourceName = resource => {
const getModuleName = name => {
const [, prefix, resource] = /^(.*!)?([^!]*)$/.exec(name);
+
+ if (resource.length > MAX_MODULE_IDENTIFIER_LENGTH) {
+ const truncatedResource = `${resource.slice(
+ 0,
+ Math.min(
+ resource.length - /* '...(truncated)'.length */ 14,
+ MAX_MODULE_IDENTIFIER_LENGTH
+ )
+ )}...(truncated)`;
+
+ return [prefix, getResourceName(truncatedResource)];
+ }
+
return [prefix, getResourceName(resource)];
};
diff --git a/test/__snapshots__/StatsTestCases.basictest.js.snap b/test/__snapshots__/StatsTestCases.basictest.js.snap
index 48cfb596442..e8fcba83fc5 100644
--- a/test/__snapshots__/StatsTestCases.basictest.js.snap
+++ b/test/__snapshots__/StatsTestCases.basictest.js.snap
@@ -1195,7 +1195,7 @@ built modules 724 bytes [built]
./templates/baz.js 38 bytes [optional] [built] [code generated]
./templates/foo.js 38 bytes [optional] [built] [code generated]
./entry.js 450 bytes [built] [code generated]
- ./templates/ lazy ^\\\\.\\\\/.*$ include: \\\\.js$ exclude: \\\\.noimport\\\\.js$ namespace object 160 bytes [optional] [built] [code generated]
+ ./templates/ lazy ^\\\\.\\\\/.*$ include: \\\\.js$ exclude: \\\\.noimport\\\\.js$ na...(truncated) 160 bytes [optional] [built] [code generated]
webpack x.x.x compiled successfully in X ms"
`;
@@ -1435,6 +1435,13 @@ asset main.js 84 bytes [emitted] (name: ma
webpack x.x.x compiled successfully in X ms"
`;
+exports[`StatsTestCases should print correct stats for max-external-module-readable-identifier 1`] = `
+"asset main.js 1.45 KiB [emitted] (name: main)
+./index.js 17 bytes [built] [code generated]
+external \\"very-very-very-very-long-external-module-readable-identifier-it-should...(truncated) 42 bytes [built] [code generated]
+webpack x.x.x compiled successfully in X ms"
+`;
+
exports[`StatsTestCases should print correct stats for max-modules 1`] = `
"asset main.js 5.47 KiB [emitted] (name: main)
./index.js 181 bytes [built] [code generated]
diff --git a/test/statsCases/max-external-module-readable-identifier/index.js b/test/statsCases/max-external-module-readable-identifier/index.js
new file mode 100644
index 00000000000..e7b7d56c8ad
--- /dev/null
+++ b/test/statsCases/max-external-module-readable-identifier/index.js
@@ -0,0 +1 @@
+require("test");
diff --git a/test/statsCases/max-external-module-readable-identifier/webpack.config.js b/test/statsCases/max-external-module-readable-identifier/webpack.config.js
new file mode 100644
index 00000000000..7f5712802a4
--- /dev/null
+++ b/test/statsCases/max-external-module-readable-identifier/webpack.config.js
@@ -0,0 +1,8 @@
+/** @type {import("../../../types").Configuration} */
+module.exports = {
+ mode: "production",
+ entry: "./index",
+ externals: {
+ test: "commonjs very-very-very-very-long-external-module-readable-identifier-it-should-be-truncated"
+ }
+};