Tree shaking, explained
Think of shaking a tree so the dead leaves fall out. If you use one function from a large library, a tree-shaking tool tries to ship only that function.
It relies on JavaScript modules, because import and export statements let the tool see what is used before the code runs. Bundlers such as Rollup, webpack and esbuild do this.
It is not magic. Code with side effects, or libraries in older formats, may be kept because the tool cannot be sure removing it is safe.
Less JavaScript means less to download, parse and run, which helps on slower phones. Shipping less in the first place, by avoiding big libraries, helps even more.



