analyze-bundle

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

analyze-to-ndjson

analyze-to-ndjson

Converts Next.js bundle analyzer binary
.data
files into grep/jq-friendly NDJSON.
将Next.js打包分析器的二进制
.data
文件转换为支持grep/jq处理的NDJSON格式。

Analyze artifacts

分析产物

This workflow pre-generates analyzer artifacts in:
  • .next/diagnostics/analyze/ndjson/routes.ndjson
  • .next/diagnostics/analyze/ndjson/sources.ndjson
  • .next/diagnostics/analyze/ndjson/output_files.ndjson
  • .next/diagnostics/analyze/ndjson/module_edges.ndjson
  • .next/diagnostics/analyze/ndjson/modules.ndjson
Focus on reading these files and using their evidence to prioritize changes.
本工作流会预生成以下路径的分析产物:
  • .next/diagnostics/analyze/ndjson/routes.ndjson
  • .next/diagnostics/analyze/ndjson/sources.ndjson
  • .next/diagnostics/analyze/ndjson/output_files.ndjson
  • .next/diagnostics/analyze/ndjson/module_edges.ndjson
  • .next/diagnostics/analyze/ndjson/modules.ndjson
建议重点读取这些文件,根据其中的信息确定优化优先级。

Output files

输出文件

FileWhat's in it
modules.ndjson
Global module registry (
id
,
ident
,
path
)
module_edges.ndjson
Module dependency graph (
from
,
to
,
kind
: sync/async)
sources.ndjson
Per-route source tree with sizes and environment flags
chunk_parts.ndjson
Granular size data: one line per (source, output_file) pair
output_files.ndjson
Per-route output files with aggregated sizes
routes.ndjson
Route-level summaries
文件内容说明
modules.ndjson
全局模块注册表(包含
id
ident
path
字段)
module_edges.ndjson
模块依赖图(包含
from
to
kind
字段:同步/异步)
sources.ndjson
按路由划分的源码树,包含体积信息和环境标识
chunk_parts.ndjson
细粒度体积数据:每个(源码, 输出文件)对应一行数据
output_files.ndjson
按路由划分的输出文件,包含汇总体积信息
routes.ndjson
路由维度的汇总信息

Browsing the output

浏览输出

Route overview

路由概览

bash
jq -s 'sort_by(-.total_compressed_size)' .next/diagnostics/analyze/ndjson/routes.ndjson
bash
jq -s 'sort_by(-.total_compressed_size)' .next/diagnostics/analyze/ndjson/routes.ndjson

Find large sources

查找大体积源码

bash
jq -s '
  group_by(.full_path)
  | map(max_by(.compressed_size))
  | sort_by(-.compressed_size)
  | .[0:10]
  | .[] | {full_path, compressed_size, size, route}
' .next/diagnostics/analyze/ndjson/sources.ndjson
bash
jq -s '
  group_by(.full_path)
  | map(max_by(.compressed_size))
  | sort_by(-.compressed_size)
  | .[0:10]
  | .[] | {full_path, compressed_size, size, route}
' .next/diagnostics/analyze/ndjson/sources.ndjson

Client-side JS

客户端JS

bash
grep '"client":true' .next/diagnostics/analyze/ndjson/sources.ndjson \
  | grep '"js":true' \
  | jq -s 'sort_by(-.compressed_size) | .[0:10] | .[] | {full_path, compressed_size}'
bash
grep '"client":true' .next/diagnostics/analyze/ndjson/sources.ndjson \
  | grep '"js":true' \
  | jq -s 'sort_by(-.compressed_size) | .[0:10] | .[] | {full_path, compressed_size}'

Module dependencies

模块依赖

bash
grep '"from":42,' .next/diagnostics/analyze/ndjson/module_edges.ndjson | jq .to
grep '"to":42,' .next/diagnostics/analyze/ndjson/module_edges.ndjson | jq .from
grep 'react-dom' .next/diagnostics/analyze/ndjson/modules.ndjson | jq '{id, path}'
bash
grep '"from":42,' .next/diagnostics/analyze/ndjson/module_edges.ndjson | jq .to
grep '"to":42,' .next/diagnostics/analyze/ndjson/module_edges.ndjson | jq .from
grep 'react-dom' .next/diagnostics/analyze/ndjson/modules.ndjson | jq '{id, path}'

Output files for a route

单路由输出文件

bash
grep '"route":"/"' .next/diagnostics/analyze/ndjson/output_files.ndjson \
  | jq -s 'sort_by(-.total_compressed_size) | .[0:10] | .[] | {filename, total_compressed_size, num_parts}'
bash
grep '"route":"/"' .next/diagnostics/analyze/ndjson/output_files.ndjson \
  | jq -s 'sort_by(-.total_compressed_size) | .[0:10] | .[] | {filename, total_compressed_size, num_parts}'

Directory tree for a route

单路由目录树

bash
grep '"route":"/"' .next/diagnostics/analyze/ndjson/sources.ndjson \
  | jq 'select(.parent_id == null)'
bash
grep '"route":"/"' .next/diagnostics/analyze/ndjson/sources.ndjson \
  | jq 'select(.parent_id == null)'