feedback icon indicating copy to clipboard operation
feedback copied to clipboard

Bundle Analysis Configuration Feedback

Open codecovdesign opened this issue 1 year ago • 45 comments

Thanks for dropping by! 👋

We'd love your feedback about the bundle analysis configuration and tool generally..

  • How was your experience setting up bundle analysis in your repo?
  • Did you experience any challenges?
  • What did you think about the documentation?
  • What would improve the set up process?
  • How can bundle analysis help you further?
  • Any general thoughts you'd like to share!

We greatly appreciate your time and thoughts - looking forward to hearing from you ❤

Codecov team

This issue is intended to share and collect feedback about the tool. If you have support needs or questions, please see our support page.

codecovdesign avatar Feb 09 '24 16:02 codecovdesign

  • How was your experience setting up bundle analysis in your repo?
    • Very easy, got it on the first attempt.
  • What did you think about the documentation?
    • Also very good! No questions.
  • How can bundle analysis help you further?
    • It would be nice if it could be incorporated as a GitHub check so that CI could auto-block if a PR increases the bundle size by a set % or bytes
  • Any general thoughts you'd like to share!
    • I deleted the bundle comment on one of my pull requests, and subsequent builds did not make the comment re-appear. It would be nice if it was able to re-create the comment in the event it got deleted and a new commit is pushed to the branch that modifies the bundle analysis.

houserx-jmcc avatar Mar 29 '24 20:03 houserx-jmcc

It would also be nice to set a threshold change to not trigger a comment. We use Vite for our builds and it seems there is often a 10-35kB variation between builds even without any substantive changes to the code or dependencies. Being able to only have the comment appear when the change matters would help to avoid people from learning to ignore it when it shows up every time.

Screenshot 2024-04-10 at 2 20 01 PM

houserx-jmcc avatar Apr 10 '24 18:04 houserx-jmcc

@houserx-jmcc thank you for the feedback 🙏

nice to set a threshold change to not trigger a comment

I've added the update proposal to this WIP issue: https://github.com/codecov/engineering-team/issues/1350

codecovdesign avatar Apr 10 '24 19:04 codecovdesign

We've been running this for a few weeks now and it was really easy to setup and has worked fine.

However, something that would be really useful is some way to filter or split bundles when reporting. In its simplest form an option to specify which file extensions to include/exclude would suffice.

We are using Vite for our project and import our styles into the entry JS file, however when building for deployment we split out the CSS stuff into a separate file. This removes the styles themselves from the bundle analysis, but all the other stuff such as images and fonts that were included are still there.

image

I'm only interested in the javascript parts (or possibly having a separate bundle for the styles/assets). Right now our bundle reports as 490kb which would be way to large for our scripts, but seeing as it is fonts in several formats and a few SVGs the size is quite OK. It makes it really hard to differentiates on changes though.

Something like this would be great to be able to do.

export default defineConfig({
  plugins: [
    codecovVitePlugin({
      enableBundleAnalysis: process.env.CODECOV_TOKEN !== undefined,
      bundleName: 'script-bundle',
      uploadToken: process.env.CODECOV_TOKEN,
      extensions: [
        '.js'
      ]
    }),
    codecovVitePlugin({
      enableBundleAnalysis: process.env.CODECOV_TOKEN !== undefined,
      bundleName: 'style-bundle',
      uploadToken: process.env.CODECOV_TOKEN,
      extensions: [
        '.css',
        '.woff',
        '.woff2',
        '.svg',
        '.png',
      ]
    })
  ]
});

Also, if you look at the screenshot above the gzip size is completely wrong for some reason.

karl-sjogren avatar Apr 11 '24 06:04 karl-sjogren

@karl-sjogren thanks for the great feedback! 🙏

some way to filter or split bundles when reporting

From my understanding of your feedback, based on that I created this issue here: https://github.com/codecov/engineering-team/issues/1562. Would you say this accurately captures the issue? If TLDR, the goal is for you to specify the files you'd like to group to have analysis of size / changes. This way the reporting is more focused on what's important to you (generic filters for JS, etc don't do the job) - Is this understanding right?

codecovdesign avatar Apr 11 '24 12:04 codecovdesign

Yes that looks good to me! Thanks!

karl-sjogren avatar Apr 11 '24 13:04 karl-sjogren

Hi. I've been using this plugin but Codecov doesn't show any data yet, only the "Configure bundle analysis" info.

Wondering what can be wrong in my setup (with Nx). Is this plugin generating some manifest file that is than uploaded to Codecov? How can I debug it. Thanks

estevaolucas avatar Apr 29 '24 16:04 estevaolucas

Hi. I've been using this plugin but Codecov doesn't show any data yet, only the "Configure bundle analysis" info.

Wondering what can be wrong in my setup (with Nx). Is this plugin generating some manifest file that is than uploaded to Codecov? How can I debug it. Thanks

@estevaolucas are you able to share your repo/config?

If it's working you should be seeing logs in your build informing you of what the plugin is doing, there is also a dryRun option that you can use to have the stats information outputted to a json file in your out dir. You can see more in out plugin config docs

nicholas-codecov avatar Apr 29 '24 17:04 nicholas-codecov

@nicholas-codecov thanks for you reply! I didn't notice there's a debug flag. That helped me to figure the issue on my setup: report was never uploading analysis due to missing token in enableBundleAnalysis to enable it. Thanks for you help

estevaolucas avatar Apr 29 '24 18:04 estevaolucas

@estevaolucas Glad you got everything all sorted! If you run into any issues let us know.

nicholas-codecov avatar Apr 29 '24 18:04 nicholas-codecov

Great work on this feature!

Just a minor comment on the documentation and a question about future implementation methods...

The documentation references Angular in the webpack plugin but I don't think this is accurate for two reasons:

I am iffy about switching to a custom builder to use this feature. Are there plans to support source maps or stats.json to analyze bundles? (I'm imagining that these files can be published the same way coverage reports are published in a CI pipeline).

grantwforsythe avatar May 04 '24 14:05 grantwforsythe

Hey @grantwforsythe thanks for reaching out!

We have on our roadmap to look into supporting esbuild directly, and we may also look into extending that to support specific cases that may arise in Angular. We will also be adding support for Angular when using Vite sooner than esbuild support.

We haven't looked into using source maps or stats.json files as of yet, but thank you for the suggestion and we will take a peak down those paths as well!

nicholas-codecov avatar May 14 '24 12:05 nicholas-codecov

Looking forward to it! Thanks for the clarification, @nicholas-codecov

grantwforsythe avatar May 14 '24 22:05 grantwforsythe

I'm trying to test this out as a POC and I'm getting this error

[codecov] `get-pre-signed-url` fetch attempt 0 failed
[codecov] Attempting to fetch `get-pre-signed-url`, attempt: 1
[codecov] `get-pre-signed-url` fetch attempt 1 failed
[codecov] Attempting to fetch `get-pre-signed-url`, attempt: 2
[codecov] `get-pre-signed-url` fetch attempt 2 failed
[codecov] `get-pre-signed-url` failed after 2 attempts
[codecov] Failed to get pre-signed URL, bad response

I'm using vite and my config looks like this

import {defineConfig} from 'vite';
import {hydrogen} from '@shopify/hydrogen/vite';
import {oxygen} from '@shopify/mini-oxygen/vite';
import {vitePlugin as remix} from '@remix-run/dev';
import tsconfigPaths from 'vite-tsconfig-paths';
import {codecovVitePlugin} from '@codecov/vite-plugin';

export default defineConfig({
  plugins: [
    hydrogen(),
    oxygen(),
    remix({
      presets: [hydrogen.preset()],
      ignoredRouteFiles: ['**/.*', '**/*.test.*', '**/styleguide.tsx'],
      future: {
        v3_fetcherPersist: false,
        v3_relativeSplatPath: false,
        v3_throwAbortReason: false,
      },
    }),
    tsconfigPaths(),
    // Put the Codecov vite plugin after all other plugins
    codecovVitePlugin({
      debug: true,
      enableBundleAnalysis: process.env.CODECOV_TOKEN !== undefined,
      bundleName: 'dist',
      uploadToken: process.env.CODECOV_TOKEN,
    }),
  ],
});

I've confirmed that my process.env.CODECOV_TOKEN is defined

What am I missing?

kayluhb avatar May 17 '24 16:05 kayluhb

Hey @kayluhb!

Hrrm first i just to note that we don't fully support Remix yet, as Vite does some funky things when it comes to client and server bundles that we'll be tackling shortly. Can you provide some info such as the repo you're trying to connect so we can filter our logs a bit more easily?

nicholas-codecov avatar May 17 '24 17:05 nicholas-codecov

Hey @kayluhb!

Hrrm first i just to note that we don't fully support Remix yet, as Vite does some funky things when it comes to client and server bundles that we'll be tackling shortly. Can you provide some info such as the repo you're trying to connect so we can filter our logs a bit more easily?

Ah, bummer... Sure thing it's the tecovas-com/tecovas-hydrogen-storefront repo that I was playing around with it on.

Thanks!

kayluhb avatar May 17 '24 18:05 kayluhb

I am iffy about switching to a custom builder to use this feature. Are there plans to support source maps or stats.json to analyze bundles? (I'm imagining that these files can be published the same way coverage reports are published in a CI pipeline).

I wanted to echo the same idea for esbuild, except esbuild generates a meta.json file instead, see https://esbuild.github.io/api/#metafile for documentation.

To elaborate, right now to enable bundle analysis for bundler X, a user would need to

  1. install codecov plugin for X via package manager
  2. configure the bundler plugin by adding ~5-10 lines of configuration to bundler X's configuration file.

With @grantwforsythe's suggestion, a user would need to

  1. configure bundler X to emit stats data, which in esbuild's case would be enabled by simply adding metafile: true to the configuration file and I'd imagine very similar for other bundlers
  2. use and configure a github action that understands and uploads different formats of metadata/stats files from different bundlers to app.codedov.io, similar to how codecov/codecov-action works currently

LuqiPan avatar May 21 '24 06:05 LuqiPan

Hi. I just took a quick, ultimately unsuccessful run at this. Nothing I couldn't solve with a bit of a closer look. I was just trying to sneak this into an existing piece of work on my project, without giving it too much thought.

I'm using Vite, running in Docker (via Docker Compose). Building with GitHub Actions.

  1. Because of the usual layers of indirection brought about by Docker, I was first tripped up by my CODECOV_TOKEN not actually making its way to Vite (and thus the Codecov plugin). Obviously the fact that this was anything but trivial is not the plugin's 'fault', but it would've been nice to be able to ask the plugin for verbose output, so I could more clearly see what was going wrong. I took about 2 minutes to look at the documentation to see if that was possible or not. If it is, and it's documented, I apologise! But it may be a sign that the docs need more work.
  2. Second issue, and one that ultimately pushed me outside my timebox and had me shelve this for now, was that the plugin couldn't work out which 'provider' (CI provider, right?) it was running within. Again, I spent a couple of minutes poking through the docs, trying to work out how the plugin determined this, and/or if it could be overridden. I didn't find anything. I vague recall GHA setting an environment variable to hint to the workflow environment that it's running inside GHA. GHA's first-party documentation is a bit of a monstrosity, and I didn't want to deal with it, so I put it down for the time being.

I'll take another look at getting it running later. I'm not looking to waste anyone's time with 'solving' these ostensibly quite trivial issues for me. I'm just voicing this because it seems like a valuable first-run experience recount.

KyeRussell avatar Aug 27 '24 05:08 KyeRussell

Hi I'm facing difficulty using @codecov/vite-plugin with react + vite + nx monorepo what could I have missed?

"vite": "5.2.7",
"@codecov/vite-plugin": "^1.1.0",
// vite.config.mts
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
import react from '@vitejs/plugin-react-swc';
import { codecovVitePlugin } from '@codecov/vite-plugin';

export default defineConfig({
  // ...other configs
  plugins: [
    react(),
    nxViteTsPaths(),
    codecovVitePlugin({
      enableBundleAnalysis: process.env.CODECOV_TOKEN !== undefined,
      bundleName: 'dist',
      uploadToken: process.env.CODECOV_TOKEN,
    }),
  ],
});
[codecov] `get-pre-signed-url` fetch attempt 1 failed
[codecov] Attempting to fetch `get-pre-signed-url`, attempt: 2
[codecov] `get-pre-signed-url` fetch attempt 2 failed
[codecov] Attempting to fetch `get-pre-signed-url`, attempt: 3
[codecov] `get-pre-signed-url` fetch attempt 3 failed
[codecov] `get-pre-signed-url` failed after 2 attempts
[codecov] Failed to get pre-signed URL, bad response

Lee-Si-Yoon avatar Sep 19 '24 07:09 Lee-Si-Yoon

@Lee-Si-Yoon Are you running this locally or in CI? If you're attempting to run this locally, you'll need to update your Vite config to load in the env vars for you, you can read more about this in the Vite env docs, and the loadEnv docs.

There's some issues with loadEnv however when running in a CI environment, that is why we provide the process.env setup by default. You can also enable debug on the config for a bit more details (we're working on improving this).

nicholas-codecov avatar Sep 19 '24 15:09 nicholas-codecov

Hi @nicholas-codecov, thank you for prompt response

I am running this locally, if I run build like below

// vite.config.mts
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
import react from '@vitejs/plugin-react-swc';
import { codecovVitePlugin } from '@codecov/vite-plugin';

export default defineConfig(() => {
  console.log('CODECOV: ', process.env.CODECOV_TOKEN);

  return {
    // ...other configs
    plugins: [
      react(),
      nxViteTsPaths(),
      codecovVitePlugin({
        debug: true,
        enableBundleAnalysis: process.env.CODECOV_TOKEN !== undefined,
        bundleName: 'dist',
        uploadToken: process.env.CODECOV_TOKEN,
      }),
    ],
  };
});

the log I get is

> vite build

CODECOV: e******* # <- env is loaded properly
vite v5.2.7 building for production...
...
[codecov] Detecting CI provider
[codecov] Detected CI provider: Local
[codecov] Using commit: null
computing gzip size (0)...
[codecov] Attempting to fetch `get-pre-signed-url`, attempt: 1
...
[codecov] `get-pre-signed-url` fetch attempt 1 failed
[codecov] Attempting to fetch `get-pre-signed-url`, attempt: 2
[codecov] `get-pre-signed-url` fetch attempt 2 failed
[codecov] Attempting to fetch `get-pre-signed-url`, attempt: 3
[codecov] `get-pre-signed-url` fetch attempt 3 failed
[codecov] `get-pre-signed-url` failed after 2 attempts
[codecov] Failed to get pre-signed URL, bad response

I assume [codecov] Using commit: null this is culprit. What could I do further to fix this?

Lee-Si-Yoon avatar Sep 20 '24 01:09 Lee-Si-Yoon

@Lee-Si-Yoon, yep that's going to be the problem. Hrrm, so when we detect that you're running locally we attempt to run Git commands to collect information from your local Git repository. Do you have any issue executing these commands in the same directory as your app?

Collects branch name:

git rev-parse --abbrev-ref HEAD

Collects commit sha:

git rev-parse HEAD

Collects repo slug:

git config --get remote.origin.url

For reference: https://github.com/codecov/codecov-javascript-bundler-plugins/blob/main/packages/bundler-plugin-core/src/utils/providers/Local.ts

nicholas-codecov avatar Sep 20 '24 11:09 nicholas-codecov

@nicholas-codecov, I tested out in github CI with debug mode enabled and by using grabbing the SHA from the GHA event context. But I still have problem uploading bundle.

rendering chunks...
[codecov] Detecting CI provider
[codecov] Detected CI provider: GitHub Actions
computing gzip size...
[codecov] Using commit: 3a5c***
[codecov] Using compareSha: f72***
[codecov] Attempting to fetch `get-pre-signed-url`, attempt: 1

...

[codecov] Failed to validate pre-signed URL
✓ built in 40.26s

So I also tried out CLI way

[codecov] Detecting CI provider
[codecov] Detected CI provider: Local
[codecov] Attempting to fetch `get-pre-signed-url`, attempt: 1
[codecov] `get-pre-signed-url` fetch attempt 1 failed
[codecov] Attempting to fetch `get-pre-signed-url`, attempt: 2
[codecov] `get-pre-signed-url` fetch attempt 2 failed
[codecov] Attempting to fetch `get-pre-signed-url`, attempt: 3
[codecov] `get-pre-signed-url` fetch attempt 3 failed
[codecov] `get-pre-signed-url` failed after 2 attempts
[codecov] Failed to get pre-signed URL, bad response: "400 - Bad Request"
[codecov] An error occurred: Error: Failed to get pre-signed URL

But does not work. Coverage is uploaded well so I do not think it is related to wrong access token or commit order. Please guide me what I can do further

Lee-Si-Yoon avatar Sep 24 '24 04:09 Lee-Si-Yoon

@Lee-Si-Yoon hrrm, let me check in with my co-worker to see if we can dive a bit deeper into the backend side of things.

nicholas-codecov avatar Sep 24 '24 10:09 nicholas-codecov

@nicholas-codecov, I tested out in github CI with debug mode enabled and by using grabbing the SHA from the GHA event context. But I still have problem uploading bundle.

rendering chunks... [codecov] Detecting CI provider [codecov] Detected CI provider: GitHub Actions computing gzip size... [codecov] Using commit: 3a5c*** [codecov] Using compareSha: f72*** [codecov] Attempting to fetch get-pre-signed-url, attempt: 1

...

[codecov] Failed to validate pre-signed URL ✓ built in 40.26s So I also tried out CLI way

[codecov] Detecting CI provider
[codecov] Detected CI provider: Local
[codecov] Attempting to fetch `get-pre-signed-url`, attempt: 1
[codecov] `get-pre-signed-url` fetch attempt 1 failed
[codecov] Attempting to fetch `get-pre-signed-url`, attempt: 2
[codecov] `get-pre-signed-url` fetch attempt 2 failed
[codecov] Attempting to fetch `get-pre-signed-url`, attempt: 3
[codecov] `get-pre-signed-url` fetch attempt 3 failed
[codecov] `get-pre-signed-url` failed after 2 attempts
[codecov] Failed to get pre-signed URL, bad response: "400 - Bad Request"
[codecov] An error occurred: Error: Failed to get pre-signed URL

But does not work. Coverage is uploaded well so I do not think it is related to wrong access token or commit order. Please guide me what I can do further

Any updates on this? Seems like I'm facing same issue. I'm using a private repository.

neelrocketbots avatar Oct 15 '24 09:10 neelrocketbots

@neelrocketbots and @Lee-Si-Yoon we've rolled out a fix for a small bug we believe may be causing this, this morning. Let us know if you continue to see this.

nicholas-codecov avatar Oct 16 '24 12:10 nicholas-codecov

@neelrocketbots and @Lee-Si-Yoon we've rolled out a fix for a small bug we believe may be causing this, this morning. Let us know if you continue to see this.

Hey, @nicholas-codecov Still facing same issue Image

neelrocketbots avatar Oct 17 '24 03:10 neelrocketbots

Hi, I'm facing the same issue as @neelrocketbots locally. However, when my build runs via github actions it works

Image

sweden-snow avatar Oct 17 '24 06:10 sweden-snow

Hey @neelrocketbots, @sweden-snow, sorry about this we need to update our docs a bit more on this, but if you're running locally with Vite you'll need to use their way of loading envs locally. If you're running in CI however, if my memory serves me correctly loadEnv won't actually load the env vars when they are injected into the environment.

cc @aj-codecov we need to update our docs/onboarding with these caveats.

nicholas-codecov avatar Oct 17 '24 10:10 nicholas-codecov

I tried to set this up for webpack4 but it looks like it is not supported - I get a Cannot read properties of undefined (reading 'tapPromise') and I see the peer dependency of webpack5 in the package.json.

I don't think I see the webpack version requirements in your documentation so I think the docs should be updated to specify webpack5 only.

md384 avatar Nov 15 '24 23:11 md384