Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[POC] Experiment with bundle analyzer CLI #71

Closed
wants to merge 1 commit into from

Conversation

AbhiPrasad
Copy link
Collaborator

@AbhiPrasad AbhiPrasad commented Feb 13, 2024

This is an experiment around #123 - opening a PR to brainstorm about the general approach.

The magic is at packages/bundle-analyzer/src/analyze.ts, which is used called by examples/plain-js/package.json via pnpm run analyze-bundle.

The problem here is that rollup is designed to work with ES modules, so it will always adds a slight transform when looking at CJS. This means the sizes are not fully accurate - but the trends over time (deltas) should be for each of the entrypoints (which are defined by your package.json).

Example stats:

{
  "version": "1",
  "bundleName": "example-rollup-bundle-cjs",
  "plugin": {
    "name": "codecov-rollup-bundle-analysis-plugin",
    "version": "1.0.0"
  },
  "builtAt": 1707794665814,
  "duration": 38,
  "bundler": { "name": "rollup", "version": "4.10.0" },
  "assets": [
    { "name": "main.js", "size": 354, "normalized": "main.js" },
    { "name": "a.js", "size": 234, "normalized": "a.js" },
    { "name": "b.js", "size": 333, "normalized": "b.js" },
    { "name": "c.js", "size": 333, "normalized": "c.js" },
    {
      "name": "common-BUKucrYi.js",
      "size": 123,
      "normalized": "common-BUKucrYi.js"
    },
    {
      "name": "_commonjsHelpers-CFO10eej.js",
      "size": 216,
      "normalized": "_commonjsHelpers-CFO10eej.js"
    }
  ],
  "chunks": [
    {
      "id": "main",
      "uniqueId": "0-main",
      "entry": true,
      "initial": false,
      "files": ["main.js"],
      "names": ["main"]
    },
    {
      "id": "a",
      "uniqueId": "1-a",
      "entry": true,
      "initial": false,
      "files": ["a.js"],
      "names": ["a"]
    },
    {
      "id": "b",
      "uniqueId": "2-b",
      "entry": true,
      "initial": false,
      "files": ["b.js"],
      "names": ["b"]
    },
    {
      "id": "c",
      "uniqueId": "3-c",
      "entry": true,
      "initial": false,
      "files": ["c.js"],
      "names": ["c"]
    },
    {
      "id": "common",
      "uniqueId": "4-common",
      "entry": false,
      "initial": false,
      "files": ["common-BUKucrYi.js"],
      "names": ["common"]
    },
    {
      "id": "_commonjsHelpers",
      "uniqueId": "5-_commonjsHelpers",
      "entry": false,
      "initial": false,
      "files": ["_commonjsHelpers-CFO10eej.js"],
      "names": ["_commonjsHelpers"]
    }
  ],
  "modules": [
    { "name": "./src/main.js", "size": 197, "chunkUniqueIds": ["0-main"] },
    {
      "name": "./src/main.js?commonjs-entry",
      "size": 0,
      "chunkUniqueIds": ["0-main"]
    },
    { "name": "./a.js", "size": 128, "chunkUniqueIds": ["1-a"] },
    { "name": "./a.js?commonjs-entry", "size": 0, "chunkUniqueIds": ["1-a"] },
    { "name": "./src/b.js", "size": 179, "chunkUniqueIds": ["2-b"] },
    {
      "name": "./src/b.js?commonjs-entry",
      "size": 0,
      "chunkUniqueIds": ["2-b"]
    },
    { "name": "./src/c.js", "size": 179, "chunkUniqueIds": ["3-c"] },
    {
      "name": "./src/c.js?commonjs-entry",
      "size": 0,
      "chunkUniqueIds": ["3-c"]
    },
    { "name": "./src/common.js", "size": 77, "chunkUniqueIds": ["4-common"] },
    {
      "name": "./commonjsHelpers.js",
      "size": 140,
      "chunkUniqueIds": ["5-_commonjsHelpers"]
    }
  ],
  "outputPath": "kappa"
}

We need to do some further processing of this stats file to remove entries that you don't care about (aka only focus on entry points).

@AbhiPrasad AbhiPrasad closed this Feb 15, 2024
@AbhiPrasad AbhiPrasad deleted the abhi-bundle-analyzer branch February 15, 2024 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant