bundle-stats vs source-map-explorer vs webpack-bundle-analyzer
前端打包分析工具
bundle-statssource-map-explorerwebpack-bundle-analyzer类似的npm包:

前端打包分析工具

前端打包分析工具用于帮助开发者理解和优化 JavaScript 应用程序的打包过程。这些工具提供可视化的分析,显示打包后文件的大小、结构和依赖关系,从而帮助识别潜在的性能瓶颈和优化机会。通过分析打包结果,开发者可以更好地管理资源,减少不必要的代码,提高应用程序的加载速度和整体性能。webpack-bundle-analyzer 是一个流行的工具,它生成交互式的可视化图表,展示每个模块在最终打包文件中的大小。source-map-explorer 则通过解析源映射文件,帮助开发者识别压缩后代码中各个部分的大小,特别是在使用代码拆分和树摇优化时。bundle-stats 提供详细的打包统计数据,支持与 CI/CD 流程集成,帮助团队在开发过程中持续监控和优化打包性能。

npm下载趋势

3 年

GitHub Stars 排名

统计详情

npm包名称
下载量
Stars
大小
Issues
发布时间
License
bundle-stats0670745 kB511 个月前MIT
source-map-explorer03,929352 kB57-Apache-2.0
webpack-bundle-analyzer012,6631.45 MB273 个月前MIT

功能对比: bundle-stats vs source-map-explorer vs webpack-bundle-analyzer

可视化分析

  • bundle-stats:

    bundle-stats 提供详细的打包统计数据,包括每个模块的大小、加载时间和依赖关系。它支持将数据导出为 JSON 格式,便于与其他工具集成和分析。

  • source-map-explorer:

    source-map-explorer 通过解析源映射文件,生成模块大小的可视化报告。它帮助你了解压缩后代码中各个部分的大小,特别是在使用源映射进行调试时。

  • webpack-bundle-analyzer:

    webpack-bundle-analyzer 提供交互式的可视化图表,展示每个模块在打包文件中的大小。你可以通过图表直观地识别大型模块和依赖关系,支持实时分析和历史对比。

集成与自动化

  • bundle-stats:

    bundle-stats 设计为与 CI/CD 流程无缝集成,支持自动化数据收集和报告。它提供 API 接口,便于与其他工具和平台集成。

  • source-map-explorer:

    source-map-explorer 通过命令行工具分析打包文件,支持与构建流程集成。它需要源映射文件来提供准确的模块大小信息。

  • webpack-bundle-analyzer:

    webpack-bundle-analyzer 可以作为 Webpack 插件集成到打包流程中,支持命令行和 Web 界面。它适合手动触发分析,也可以与 CI 流程结合。

数据输出

  • bundle-stats:

    bundle-stats 提供结构化的 JSON 数据,包含详细的打包统计信息。数据格式化,便于自动化处理和分析。

  • source-map-explorer:

    source-map-explorer 生成模块大小的文本报告,支持 HTML 输出。报告中包含每个模块的大小和路径,便于分析。

  • webpack-bundle-analyzer:

    webpack-bundle-analyzer 生成可视化的 HTML 报告,展示打包文件的结构和模块大小。报告可以实时查看,也支持导出。

支持的打包工具

  • bundle-stats:

    bundle-stats 主要针对 Webpack,但也支持其他打包工具。它可以分析多种格式的打包输出,提供灵活的统计功能。

  • source-map-explorer:

    source-map-explorer 支持任何生成源映射文件的打包工具,如 Webpack、Rollup 和 Parcel。它依赖于源映射文件进行分析。

  • webpack-bundle-analyzer:

    webpack-bundle-analyzer 专为 Webpack 设计,支持 Webpack 4 和 5。它可以分析任何使用 Webpack 打包的项目。

代码示例

  • bundle-stats:

    使用 bundle-stats 生成打包统计

    const BundleStatsPlugin = require('bundle-stats-webpack-plugin');
    
    module.exports = {
      plugins: [
        new BundleStatsPlugin(),
      ],
    };
    
  • source-map-explorer:

    使用 source-map-explorer 分析打包文件

    npx source-map-explorer dist/bundle.js dist/bundle.js.map
    
  • webpack-bundle-analyzer:

    使用 webpack-bundle-analyzer 进行打包分析

    const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
    
    module.exports = {
      plugins: [
        new BundleAnalyzerPlugin(),
      ],
    };
    

如何选择: bundle-stats vs source-map-explorer vs webpack-bundle-analyzer

  • bundle-stats:

    选择 bundle-stats 如果你需要全面的打包统计数据,并希望将分析结果集成到 CI/CD 流程中。它提供结构化的数据,便于自动化监控和优化打包性能。

  • source-map-explorer:

    选择 source-map-explorer 如果你关注压缩后代码的大小,并希望通过源映射文件深入了解各个模块的大小。它特别适合分析使用代码拆分和树摇优化后的项目。

  • webpack-bundle-analyzer:

    选择 webpack-bundle-analyzer 如果你需要一个直观的可视化工具来分析 Webpack 打包文件,识别大型模块和依赖关系。它适合需要交互式分析和实时查看打包结果的开发者。

bundle-stats的README

BundleStats screenshot

Demos: Bundle analysis comparison· Bundle analysis

BundleStats

Analyze bundle stats(bundle size, assets, modules, packages) and compare the results between different builds. Support for webpack/rspack and vite/rolldown/rollup using rollup-plugin-webpack-stats.

Node version GitHub action Socket CodeQL

RelativeCI

- Bundle size and totals by file type(css, js, img, etc)
- Insights: duplicate packages, new packages
- Initial JS/CSS, Cache invalidation, and other bundle metrics
- Assets report (entrypoint, initial, types, changed, delta)
- Modules report (changed, delta, chunks, duplicate count and percentage)
- Packages report (count, duplicate, changed, delta)
:star: Side by side comparison for multiple builds

Table of Contents

Install as global dependency

npm install -g bundle-stats

or

yarn global add bundle-stats

Install as dev dependency

npm install --dev bundle-stats

or

yarn add --dev bundle-stats

Output stats

The CLI expects stats files that follow the webpack stats schema. Follow the guides below to learn how to export compatible output from webpack/rspack or from vite/rollup/rolldown.

webpack/rspack stats

You can customize the contents of the generated stats file by configuring the webpack stats options:

{
  stats: {
    // required
    assets: true,
    chunks: true,
    modules: true,
    // optional
    builtAt: true,
    hash: true
  }
}

To output the the webpack stats JSON file you can use:

1. webpack-cli --json option:

npx webpack --mode production --json artifacts/webpack-stats.json

Guide & examples: How to output webpack stats using the CLI

2. using webpack-stats-plugin

Guide & examples: How to output webpack stats JSON file using webpack-stats-plugin

Learn more

vite/rollup/rolldown stats

Guide & examples: How to output stats in Vite

Learn more

Usage

$ bundle-stats -h
Usage: bundle-stats OPTIONS [WEBPACK_STATS_FILE]...

Options:
      --demo               Generate demo reports      [boolean] [default: false]
      --compare            Use local saved stats for comparison
                                                       [boolean] [default: true]
      --baseline           Save current stats as baseline
                                                      [boolean] [default: false]
      --baseline-filepath  Baseline filepath, default:
                           node_modules/.cache/bundle-stats/baseline.json
                                                                        [string]
      --html               Save HTML report            [boolean] [default: true]
      --json               Save JSON data             [boolean] [default: false]
  -d, --out-dir            Output directory                             [string]
  -h, --help               Show help                                   [boolean]
  -v, --version            Show version number                         [boolean]
$ bundle-stats --html --json __fixtures__/webpack-stats-0.json __fixtures__/webpack-stats-1.json
  ✔ Read Webpack stat files
  ✔ Read baseline data
  ↓ Write baseline data [skipped]
    → Not a baseline job (see --baseline).
  ✔ Gather data
  ✔ Generate reports
  ✔ Save reports

┌─────────────────────────────────────────────────┐
│                                                 │
│   Bundle size decreased with 3.06KB (-0.38%).   │
│                                                 │
└─────────────────────────────────────────────────┘

Artifacts saved:
- ./dist/bundle-stats.html
- ./dist/bundle-stats.json

Compare mode

In compare mode, the metrics are compared against an existing(node_modules/.cache/bundle-stats/baseline.json) Webpack stats file(baseline). To generate the baseline webpack stats, use --baseline option:

# Checkout to the branch/tag/commit where you want to generate the baseline
$ git checkout master

# Build your application
$ npm run build

# Run bundle-stats with --baseline option. This will save the baseline data on node_modules/.cache/bundle-stats/baseline.json
$ bundle-stats --baseline artifacts/webpack-stats.json
 ✔ Read Webpack stat files
 ↓ Read baseline data [skipped]
   → Missing baseline stats, see "--baseline" option.
 ✔ Write baseline data
 ✔ Process data
 ✔ Generate reports
 ✔ Save reports

┌─────────────────────────────────────────────────┐
│                                                 │
│   Bundle size decreased with 3.06KB (-0.38%).   │
│                                                 │
└─────────────────────────────────────────────────┘

Artifacts saved:
- ./dist/bundle-stats.html
# Checkout to the working branch/tag/commit
$ git checkout MY_FEATURE_BRANCH

# Build your application
$ npm run build

# Run bundle-stats - the report is going to compare the current data against the generated baseline
$ bundle-stats artifacts/webpack-stats.json
 ✔ Read Webpack stat files
 ✔ Read baseline data
 ↓ Write baseline data [skipped]
   → Not a baseline job (see --baseline).
 ✔ Process data
 ✔ Generate reports
 ✔ Save reports

┌─────────────────────────────────────────────────┐
│                                                 │
│   Bundle size decreased with 3.06KB (-0.38%).   │
│                                                 │
└─────────────────────────────────────────────────┘

Artifacts saved:
- ./dist/bundle-stats.html

The option can be disabled using --no-compare option.

Framework specific plugins

Related projects

:cyclone: relative-ci.com

Automated bundle analysis, reviews and monitoring - Quickly identify and fix bundle regressions before shipping to production.

:rocket: Get started

:first_quarter_moon: relative-ci/compare

Standalone web application to compare Webpack/Lighthouse/Browsertime stats.

Compare bundle stats

:zap: bundle-stats-action

Github Action that generates bundle-stats reports.

Other packages

bundle-stats-webpack-plugin

npm npm

Webpack plugin to generate bundle stats report for webpack/rspack.

gatsby-plugin-bundle-stats

npm npm

Gatsby plugin for bundle-stats.

next-plugin-bundle-stats

npm npm

Next.js plugin for bundle-stats.

rollup-plugin-bundle-stats

npm npm

Rollup plugin to generate bundle stats report for vite/rolldown/rollup.