Search code examples
performancescala.jsscalajs-bundler

How to break down the size of scala.js JS output


There exist a few webpack bundle analysis scripts that show a list of included modules along with their sizes. However, Scala.js emits one big module for all the Scala code, so those tools can't look into it.

As both a library author and an end user of other Scala.js libraries I want to know how much various Scala packages / classes contribute to my bundle size.

I understand that Scala.js optimization makes it impossible to say that a given library weights exactly X Kb, so I'm interested in a solution that looks at a specific bundle.

Currently the best I can do is search for "com.package.name in the generated JS file, and judge the density of result indicators on the scroll bar, but that's obviously tremendously suboptimal.

So my question is, are there any tools or even half baked scripts that could improve on what I'm doing?


Solution

  • Finally found a good solution – with the right sbt config source-map-explorer npm package does exactly what I need based on sourcemaps (of course!). It shows the direct impact of individual Scala classes on bundle size.

    Source: Scala.js issue #3556