ai / size-limit

Calculate the real cost to run your JS app or lib to keep good performance. Show error in pull request if the cost exceeds the limit.
MIT License
6.52k stars 1.82k forks source link

Supporting `--why` for esbuild #302

Closed unional closed 1 year ago

unional commented 1 year ago

Currently it does not:

 ERROR  Argument --why works only with @size-limit/webpack plugin and @size-limit/webpack-why plugin.
        You can add Bundle Analyzer to you own bundler.

Maybe it is possible now?

https://github.com/evanw/esbuild/issues/15 https://www.npmjs.com/package/esbuild-visualizer

Want to see how to make them work with size-limit

ai commented 1 year ago

Interesting to know about esbuild-visualizer.

However, I will not have time for this feature. Can I ask you to make a PR adding new @size-limit/esbuild-why package using esbuild-visualizer?

unional commented 1 year ago

I can take a look when I get a chance.

unional commented 1 year ago

Hi @ai , I'm also done with it. One thing is that esbuild-visualizer seems to only output a html result. That means we have to save it somewhere.

webpack-why have a saveBundle option. Is there a sensible default for that? Or esbuild usage would require both why and saveBundle to be defined?

unional commented 1 year ago

FYI I have a private project that esbuild size returns 116 kb while webpack return 22 kb. I wonder why there is such a big different. First guess is that esbuild one didn't do tree shaking on the dependencies.

unional commented 1 year ago

Seems like there is some problem.


pnpm add -D @size-limit/preset-small-lib
 ERR_PNPM_NO_MATCHING_VERSION_INSIDE_WORKSPACE  In : No matching version found for @size-limit/esbuild@8.2.0 inside the workspace
 ```

The version strings are not updated during publish:

https://www.npmjs.com/package/@size-limit/preset-small-lib?activeTab=explore

Maybe they should be `workspace:^` or even `workspace:*`?
ai commented 1 year ago

Nope, the problem is with npm. When I started to release a small 8.2.1 fix, they block releasing some packages.

Install 8.2.0 for every package.

I will try to release 8.2.1 again later.

ai commented 1 year ago

I released the fix in 8.2.2.

unional commented 1 year ago

The 8.2.2 still have the same problem.

Seems like when you run pnpm bump, the preset-app, preset-big-lib, and preset-small-lib dependencies fields didn't get updated somehow.

I run it locally here is it seems to be working: image

ai commented 1 year ago

The 8.2.2 still have the same problem.

What exactly problem do you have?

unional commented 1 year ago

What exactly problem do you have?

Unable to install @size-limit/preset-small-lib

pnpm add -D @size-limit/preset-small-lib
 ERR_PNPM_NO_MATCHING_VERSION_INSIDE_WORKSPACE  In : No matching version found for @size-limit/esbuild@8.2.2 inside the workspace

Because the version string workspace:8.2.2 is invalid. It should be 8.2.2

unional commented 1 year ago

btw, I use changsets in my libraries to manage releases. It works well with pnpm and monorepo. 🍻

ai commented 1 year ago

Unable to install @size-limit/preset-small-lib

Did you update size-limit and @size-limit/esbuild to 8.2.2?

Because the version string workspace:8.2.2 is invalid. It should be 8.2.2

We have workspace:8.2.2 only in devDependencies (which we remove on release). peerDependencies uses 8.2.2.

unional commented 1 year ago

We have workspace:8.2.2 only in devDependencies (which we remove on release). peerDependencies uses 8.2.2.

It's not. See the screenshot above. preset-* is dependencies and somehow not updated

The @size-limit/preset-small-lib uses @size-limit/esbuild as dependencies, so no need to install it explicitly.

ai commented 1 year ago

Got it. Try 8.2.3.

unional commented 1 year ago

Working now 🎉