object
string
stats
选项允许您精确控制显示哪些捆绑信息。如果您不想使用 quiet
或 noInfo
,因为您想要一些捆绑信息但不是全部,这可能是一个不错的折中方案。
module.exports = {
//...
stats: 'errors-only',
};
Webpack 为统计输出提供了几个预设
预设 | 替代方案 | 描述 |
---|---|---|
'errors-only' | 无 | 仅在发生错误时输出 |
'errors-warnings' | 无 | 仅在发生错误和警告时输出 |
'minimal' | 无 | 仅在发生错误或新编译时输出 |
'none' | false | 不输出任何内容 |
'normal' | true | 标准输出 |
'verbose' | 无 | 输出所有内容 |
'detailed' | 无 | 输出除 chunkModules 和 chunkRootModules 之外的所有内容 |
'summary' | 无 | 输出 webpack 版本、警告计数和错误计数 |
可以指定您希望在统计信息输出中看到哪些信息。
当选项未定义时,统计信息选项的备用值。它优先于本地 webpack 默认值。
module.exports = {
//...
stats: {
all: undefined,
},
};
boolean = true
告诉 stats
是否显示资源信息。将 stats.assets
设置为 false
可将其隐藏。
module.exports = {
//...
stats: {
assets: false,
},
};
string = 'id'
告诉 stats
根据给定字段对资源进行排序。所有排序字段都可以用作 stats.assetsSort
的值。在值中使用 !
前缀可以按给定字段反转排序顺序。
module.exports = {
//...
stats: {
assetsSort: '!size',
},
};
number = 15
告诉 stats
应显示多少个资源项(组将被折叠以适应此空间)。
module.exports = {
//...
stats: {
assetsSpace: 15,
},
};
boolean = true
告诉 stats
是否添加构建日期和构建时间信息。将 stats.builtAt
设置为 false
可将其隐藏。
module.exports = {
//...
stats: {
builtAt: false,
},
};
stats.cachedModules
的旧版本。
boolean = true
告诉 stats
是否添加有关缓存资源的信息。将 stats.cachedAssets
设置为 false
将告诉 stats
仅显示已发出的文件(而不是已构建的文件)。
module.exports = {
//...
stats: {
cachedAssets: false,
},
};
boolean = true
告诉 stats
是否添加有关缓存(未构建)模块的信息。
module.exports = {
//...
stats: {
cachedModules: false,
},
};
boolean = true
告诉 stats
是否添加有关子项的信息。
module.exports = {
//...
stats: {
children: false,
},
};
boolean = true
在 chunk 组中显示辅助资源。
module.exports = {
//...
stats: {
chunkGroupAuxiliary: false,
},
};
boolean = true
显示 chunk 组的子项(例如预取、预加载的 chunk 和资源)。
module.exports = {
//...
stats: {
chunkGroupChildren: false,
},
};
number
chunk 组中显示的资源数量限制。
module.exports = {
//...
stats: {
chunkGroupMaxAssets: 5,
},
};
boolean = true
告诉 stats
是否添加有关 namedChunkGroups
的信息。
module.exports = {
//...
stats: {
chunkGroups: false,
},
};
boolean = true
告诉 stats
是否将有关已构建模块的信息添加到 chunk 信息中。
module.exports = {
//...
stats: {
chunkModules: false,
},
};
number = 10
告诉 stats
应显示多少个 chunk 模块项(组将被折叠以适应此空间)。
module.exports = {
//...
stats: {
chunkModulesSpace: 15,
},
};
boolean = true
告诉 stats
是否添加有关 chunk 起源和 chunk 合并的信息。
module.exports = {
//...
stats: {
chunkOrigins: false,
},
};
boolean = false
告诉 stats
显示 chunk 的父级、子级和同级。
module.exports = {
//...
stats: {
chunkRelations: false,
},
};
boolean = true
告诉 stats
是否添加有关 chunk 的信息。将 stats.chunks
设置为 false
会使输出更简洁。
module.exports = {
//...
stats: {
chunks: false,
},
};
string = 'id'
告诉 stats
根据给定字段对 chunk 进行排序。所有排序字段都可以用作 stats.chunksSort
的值。在值中使用 !
前缀可以按给定字段反转排序顺序。
module.exports = {
//...
stats: {
chunksSort: 'name',
},
};
boolean = false
{ bold?: string, cyan?: string, green?: string, magenta?: string, red?: string, yellow?: string }
告诉 stats
是否以不同颜色输出。
module.exports = {
//...
stats: {
colors: true,
},
};
它也可以作为 CLI 标志使用
npx webpack --stats-colors
禁用
npx webpack --no-stats-colors
您可以使用 ANSI 转义序列指定自己的终端输出颜色
module.exports = {
//...
colors: {
green: '\u001b[32m',
},
};
字符串
统计信息的基本目录,一个用于缩短请求信息的绝对路径。
const path = require('path');
module.exports = {
//...
stats: {
context: path.resolve(__dirname, 'src/components'),
},
};
默认情况下,使用 context
的值或 Node.js 当前工作目录。
boolean
告诉 stats
是否显示作为 chunk 中其他模块依赖项的 chunk 模块。
module.exports = {
//...
stats: {
dependentModules: false,
},
};
boolean = false
告诉 stats
是否显示每个模块到入口点的距离。
module.exports = {
//...
stats: {
depth: true,
},
};
boolean = true
"auto"
告诉 stats
是否显示入口点及其对应的捆绑包。
module.exports = {
//...
stats: {
entrypoints: false,
},
};
当 stats.entrypoints
设置为 'auto'
时,webpack 将自动决定是否在统计输出中显示入口点。
boolean = false
告诉 stats
是否显示 --env
信息。
module.exports = {
//...
stats: {
env: true,
},
};
boolean
"auto"
告诉 stats
是否在输出中包含错误的 cause
属性。默认为 true
。
module.exports = {
//...
stats: {
errorCause: true,
},
};
boolean
"auto"
告诉 stats
是否将详细信息添加到错误中。默认为 'auto'
,当错误数量为 2 个或更少时显示错误详细信息。
module.exports = {
//...
stats: {
errorDetails: false,
},
};
boolean
"auto"
告诉 stats
是否在输出中包含 AggregateError
实例的错误数组。默认为 true
。
当单个错误由多个底层错误组成时非常有用,可以更深入地了解分组错误结构。
module.exports = {
//...
stats: {
errorErrors: true,
},
};
boolean = true
告诉 stats
是否显示错误的堆栈跟踪。
module.exports = {
//...
stats: {
errorStack: false,
},
};
boolean = true
告诉 stats
是否显示错误。
module.exports = {
//...
stats: {
errors: false,
},
};
boolean = true
添加错误计数。
module.exports = {
//...
stats: {
errorsCount: false,
},
};
number
告诉 stats
限制显示错误时分配的行数。
module.exports = {
//...
stats: {
errorsSpace: 5,
},
};
array = []: string | RegExp | function (assetName) => boolean
string
RegExp
function (assetName) => boolean
告诉 stats
排除匹配的资源信息。这可以通过 string
、RegExp
或一个以资源名称作为参数并返回 boolean
的 function
来完成。stats.excludeAssets
可以是上述任何一种的 array
。
module.exports = {
//...
stats: {
excludeAssets: [
'filter',
/filter/,
(assetName) => assetName.contains('moduleA'),
],
},
};
array = []: string | RegExp | function (assetName) => boolean
string
RegExp
function (assetName) => boolean
boolean: false
告诉 stats
排除匹配的模块信息。这可以通过 string
、RegExp
或一个以模块源作为参数并返回 boolean
的 function
来完成。stats.excludeModules
可以是上述任何一种的 array
。stats.excludeModules
的配置与 stats.exclude
的配置值合并。
module.exports = {
//...
stats: {
excludeModules: ['filter', /filter/, (moduleSource) => true],
},
};
将 stats.excludeModules
设置为 false
将禁用排除行为。
module.exports = {
//...
stats: {
excludeModules: false,
},
};
boolean
告诉 stats
是否根据资源与 chunk 的关系进行分组。
module.exports = {
//...
stats: {
groupAssetsByChunk: false,
},
};
boolean
告诉 stats
是否根据资源状态(已发出、已比较待发出或已缓存)进行分组。
module.exports = {
//...
stats: {
groupAssetsByEmitStatus: false,
},
};
boolean
告诉 stats
是否根据资源的扩展名进行分组。
module.exports = {
//...
stats: {
groupAssetsByExtension: false,
},
};
boolean
告诉 stats
是否根据资源的资产信息(不可变、开发、热模块替换等)进行分组。
module.exports = {
//...
stats: {
groupAssetsByInfo: false,
},
};
boolean
告诉 stats
是否根据资源的路径进行分组。
module.exports = {
//...
stats: {
groupAssetsByPath: false,
},
};
boolean
告诉 stats
是否根据模块的属性(错误、警告、资源、可选、孤立或依赖)进行分组。
module.exports = {
//...
stats: {
groupModulesByAttributes: false,
},
};
boolean
告诉 stats
是否根据模块的缓存状态(已缓存或已构建且可缓存)进行分组。
module.exports = {
//...
stats: {
groupModulesByCacheStatus: true,
},
};
boolean
告诉 stats
是否根据模块的扩展名进行分组。
module.exports = {
//...
stats: {
groupModulesByExtension: true,
},
};
boolean
告诉 stats
是否根据模块的层级进行分组。
module.exports = {
//...
stats: {
groupModulesByLayer: true,
},
};
boolean
告诉 stats
是否根据模块的路径进行分组。
module.exports = {
//...
stats: {
groupModulesByPath: true,
},
};
boolean
告诉 stats
是否根据模块的类型进行分组。
module.exports = {
//...
stats: {
groupModulesByType: true,
},
};
boolean
按其源模块对 reasons
进行分组,以避免大量原因。
module.exports = {
//...
stats: {
groupReasonsByOrigin: true,
},
};
boolean = true
告诉 stats
是否添加有关编译哈希的信息。
module.exports = {
//...
stats: {
hash: false,
},
};
boolean = false
告诉 stats
添加模块和 chunk 的 ID。
module.exports = {
//...
stats: {
ids: true,
},
};
string = 'info': 'none' | 'error' | 'warn' | 'info' | 'log' | 'verbose'
boolean
告诉 stats
是否添加日志输出。
'none'
, false
- 禁用日志记录'error'
- 仅错误'warn'
- 仅错误和警告'info'
- 错误、警告和信息消息'log'
, true
- 错误、警告、信息消息、日志消息、组、清除。折叠组以折叠状态显示。'verbose'
- 记录除调试和跟踪之外的所有内容。折叠组以展开状态显示。module.exports = {
//...
stats: {
logging: 'verbose',
},
};
array = []: string | RegExp | function (name) => boolean
string
RegExp
function (name) => boolean
告诉 stats
包含指定日志记录器(如插件或加载器)的调试信息。当 stats.logging
设置为 false
时,stats.loggingDebug
选项将被忽略。
module.exports = {
//...
stats: {
loggingDebug: [
'MyPlugin',
/MyPlugin/,
/webpack/, // To get core logging
(name) => name.contains('MyPlugin'),
],
},
};
boolean = true
在日志输出中为错误、警告和跟踪启用堆栈跟踪。将 stats.loggingTrace
设置为 `false` 可隐藏跟踪。
module.exports = {
//...
stats: {
loggingTrace: false,
},
};
boolean = true
告诉 stats
是否添加模块内部资源的信息。将 stats.moduleAssets
设置为 false
可将其隐藏。
module.exports = {
//...
stats: {
moduleAssets: false,
},
};
boolean = true
告诉 stats
显示依赖项以及警告/错误的来源。stats.moduleTrace
自 webpack 2.5.0 起可用。
module.exports = {
//...
stats: {
moduleTrace: false,
},
};
boolean = true
告诉 stats
是否添加有关已构建模块的信息。
module.exports = {
//...
stats: {
modules: false,
},
};
string = 'id'
告诉 stats
根据给定字段对模块进行排序。所有排序字段都可以用作 stats.modulesSort
的值。在值中使用 !
前缀可以按给定字段反转排序顺序。
module.exports = {
//...
stats: {
modulesSort: 'size',
},
};
number = 15
告诉 stats
应显示多少个模块项(组将被折叠以适应此空间)。
module.exports = {
//...
stats: {
modulesSpace: 15,
},
};
boolean
告诉 stats
是否添加有关嵌套在其他模块中的模块的信息(例如模块串联)。
module.exports = {
//...
stats: {
nestedModules: true,
},
};
number = 10
告诉 stats
应显示多少个嵌套模块项(组将被折叠以适应此空间)。
module.exports = {
//...
stats: {
nestedModulesSpace: 15,
},
};
boolean
告诉 stats
显示模块优化中止的原因。
module.exports = {
//...
stats: {
optimizationBailout: false,
},
};
boolean = false
告诉 stats
是否隐藏孤立
模块。如果模块未包含在任何 chunk 中,则它是孤立
模块。默认情况下,孤立模块在 stats
中是隐藏的。
module.exports = {
//...
stats: {
orphanModules: true,
},
};
boolean = true
告诉 stats
显示 outputPath
。
module.exports = {
//...
stats: {
outputPath: false,
},
};
boolean = true
告诉 stats
在文件大小超过 performance.maxAssetSize
时显示性能提示。
module.exports = {
//...
stats: {
performance: false,
},
};
string
boolean: false
module.exports = {
//...
stats: {
preset: 'minimal',
},
};
将 stats.preset
的值设置为 false
会告诉 webpack 使用 'none'
统计信息预设。
boolean = false
告诉 stats
显示模块的导出。
module.exports = {
//...
stats: {
providedExports: true,
},
};
boolean = true
告诉 stats
显示 publicPath
。
module.exports = {
//...
stats: {
publicPath: false,
},
};
boolean = true
告诉 stats
添加有关模块被包含的原因的信息。
module.exports = {
//...
stats: {
reasons: false,
},
};
number
显示 reasons
的空间(组将被折叠以适应此空间)。
module.exports = {
//...
stats: {
reasonsSpace: 1000,
},
};
boolean = false
告诉 stats
是否添加有关与其他资源相关的资源(例如资源的 SourceMaps)的信息。
module.exports = {
//...
stats: {
relatedAssets: true,
},
};
boolean = true
告诉 stats
是否添加有关运行时模块的信息。
module.exports = {
//...
stats: {
runtimeModules: false,
},
};
boolean = false
告诉 stats
添加模块的源代码。
module.exports = {
//...
stats: {
source: true,
},
};
boolean = true
告诉 stats
添加计时信息。
module.exports = {
//...
stats: {
timings: false,
},
};
boolean = false
告诉 stats
是否显示模块的哪些导出被使用。
module.exports = {
//...
stats: {
usedExports: true,
},
};
boolean = true
告诉 stats
添加有关使用的 webpack 版本的信息。
module.exports = {
//...
stats: {
version: false,
},
};
boolean = true
告诉 stats
添加警告。
module.exports = {
//...
stats: {
warnings: false,
},
};
boolean = true
添加警告计数。
module.exports = {
//...
stats: {
warningsCount: false,
},
};
array = []: string | RegExp | function (warning) => boolean
string
RegExp
function (warning) => boolean
告诉 stats
排除匹配给定过滤器的警告。这可以通过 string
、RegExp
或一个以警告作为参数并返回 boolean
的 function
来完成。stats.warningsFilter
可以是上述任何一种的 array
。
module.exports = {
//...
stats: {
warningsFilter: ['filter', /filter/, (warning) => true],
},
};
number
告诉 stats
限制显示警告时分配的行数。
module.exports = {
//...
stats: {
warningsSpace: 5,
},
};
对于 assetsSort
、chunksSort
和 modulesSort
,您可以通过以下几个可能的字段对项进行排序
'id'
- 项的 ID,'name'
- 导入时分配给项的名称,'size'
- 项的大小(以字节为单位),'chunks'
- 项源自的 chunk(例如,如果一个 chunk 有多个子 chunk:子 chunk 将根据其主 chunk 进行分组),'errors'
- 项中的错误数量,'warnings'
- 项中的警告数量,'failed'
- 项是否编译失败,'cacheable'
- 项是否可缓存,'built'
- 资源是否已构建,'prefetched'
- 资源是否将被预取,'optional'
- 资源是否可选。'identifier'
- 项的标识符。'index'
- 项的处理索引。'index2'
'profile'
'issuer'
- 发行者的标识符。'issuerId'
- 发行者的 ID。'issuerName'
- 发行者的名称。'issuerPath'
- 完整的发行者对象。没有真正的必要按此字段排序。如果您想使用预设之一,例如 'minimal'
,但仍想覆盖某些规则:请指定所需的 `stats.preset`,然后在后面添加自定义或额外的规则。
webpack.config.js
module.exports = {
//..
stats: {
preset: 'minimal',
moduleTrace: true,
errorDetails: true,
},
};