使用webpack编译源码时,可以生成一个包含模块统计信息的JSON文件,可以用来分析应用中的依赖关系图,进行优化编译速度。
这个文件由以下CLI命令生成。
npx webpack --profile --json=compilation-stats.json
配置结构(Structure)
输出JSON文件的顶层结构比较简单,但也包含部分嵌套数据结构。
{
'version': '5.9.0', // 用来编译的 webpack 版本
'hash': '11593e3b3ac85436984a', // 编译的特定哈希值
'time': 2469, // 编译时间(毫秒)
'publicPath': 'auto',
'outputPath': '/', // webpack 的输出目录路径
'assetsByChunkName': {
// 输出资源对应的 Chunk 名称
'main': [
'web.js?h=11593e3b3ac85436984a'
],
'named-chunk': [
'named-chunk.web.js'
],
'other-chunk': [
'other-chunk.js',
'other-chunk.css'
]
},
'assets': [
// [asset objects](#asset-objects) 列表
],
'chunks': [
// [chunk objects](#chunk-objects) 列表
],
'modules': [
// [module objects](#module-objects) 列表
],
'entryPoints': {
// [entry objects](#entry-objects) 列表
},
'errors': [
// [error objects](#errors-and-warnings) 列表
],
'errorsCount': 0, // 错误个数
'warnings': [
// [warning objects](#errors-and-warnings) 列表
],
'warningsCount': 0, // 告警个数
}