mf-perf

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
Step 1: Call the
mf-context
Skill (pass
$ARGUMENTS
) to collect MFContext.
Step 2: Serialize MFContext to JSON and pass it to the check script via the
--context
argument:
bash
node scripts/performance-check.js --context '<MFContext-JSON>'
Provide recommendations for each item in the output
results
and
context.bundler.name
:
PERF · info —
dev.disableAssetsAnalyze
(applies to all projects)
  • Disabling bundle size analysis during local development significantly improves HMR speed
  • Add to the Rsbuild config:
    js
    dev: { disableAssetsAnalyze: true }
PERF · info — Rspack
splitChunks
optimization
(shown only when
bundler.name
is
rspack
or
rsbuild
)
  • Setting
    splitChunks.chunks
    to
    "async"
    reduces initial bundle size and speeds up first-screen loading
  • Add to the build config:
    js
    output: { splitChunks: { chunks: 'async' } }
PERF · info — TypeScript DTS optimization (shown only when
typescript
dependency is detected)
  • If type generation (DTS) is the main bottleneck, options include:
    1. Temporarily disable DTS: set
      dts: false
      in the
      @module-federation/enhanced
      config
    2. Switch to
      ts-go
      for significantly faster type generation
Step 3: After presenting the DTS recommendation, ask the user:
"Would you like me to automatically try switching to
ts-go
and verify compatibility?"
If the user confirms, execute the following steps in order:
  1. Backup — copy the current generated type output directory (e.g.
    @mf-types/
    ) to a timestamped backup path such as
    @mf-types.bak.<timestamp>/
  2. Configure — set
    dts.generateTypes.compilerInstance = "tsgo"
    in the Module Federation config
  3. Install — install the required package:
    bash
    npm install @typescript/native-preview --save-dev
    (use the project's actual package manager from MFContext)
  4. Regenerate — run:
    bash
    npx mf dts
  5. Verify — diff the newly generated type output against the backup:
    • If the output is identical: inform the user that
      ts-go
      is compatible and the switch is safe; offer to remove the backup
    • If the output differs: revert the config change, restore the backup, and explain clearly what differs (e.g. missing declarations, changed signatures) so the user can decide whether the difference is acceptable
Webpack projects do not show Rspack-specific entries to avoid irrelevant suggestions.
步骤1:调用
mf-context
Skill(传入
$ARGUMENTS
)来收集MFContext。
步骤2:将MFContext序列化为JSON,通过
--context
参数传递给检查脚本:
bash
node scripts/performance-check.js --context '<MFContext-JSON>'
针对输出的
results
context.bundler.name
中的每个项提供建议:
PERF · 信息 —
dev.disableAssetsAnalyze
(适用于所有项目)
  • 在本地开发期间禁用包大小分析可显著提升HMR速度
  • 添加到Rsbuild配置中:
    js
    dev: { disableAssetsAnalyze: true }
PERF · 信息 — Rspack
splitChunks
优化
(仅当
bundler.name
rspack
rsbuild
时显示)
  • splitChunks.chunks
    设置为
    "async"
    可减小初始包大小并加快首屏加载速度
  • 添加到构建配置中:
    js
    output: { splitChunks: { chunks: 'async' } }
PERF · 信息 — TypeScript DTS优化(仅当检测到
typescript
依赖时显示)
  • 如果类型生成(DTS)是主要瓶颈,可选方案包括:
    1. 临时禁用DTS:在
      @module-federation/enhanced
      配置中设置
      dts: false
    2. 切换到
      ts-go
      以大幅提升类型生成速度
步骤3:在展示DTS建议后,询问用户:
"是否需要我自动尝试切换到
ts-go
并验证兼容性?"
如果用户确认,按以下顺序执行步骤:
  1. 备份 — 将当前生成的类型输出目录(例如
    @mf-types/
    )复制到带时间戳的备份路径,如
    @mf-types.bak.<timestamp>/
  2. 配置 — 在Module Federation配置中设置
    dts.generateTypes.compilerInstance = "tsgo"
  3. 安装 — 安装所需包:
    bash
    npm install @typescript/native-preview --save-dev
    (使用MFContext中项目实际的包管理器)
  4. 重新生成 — 运行:
    bash
    npx mf dts
  5. 验证 — 将新生成的类型输出与备份进行对比:
    • 如果输出完全一致:告知用户
      ts-go
      兼容,切换是安全的;可选择移除备份
    • 如果输出存在差异:还原配置更改,恢复备份,并清晰说明差异点(例如缺少声明、签名变更),以便用户决定差异是否可接受
Webpack项目不会显示Rspack相关条目,以避免无关建议。