Hacker News new | ask | show | jobs
by eyelidlessness 1716 days ago
What ESBuild offers over plain ESM is:

- fast TypeScript/JSX compile

- bundling shared code to reduce request waterfall/splitting to reduce redundancy

- bundle optimization (tree shaking/dead code elimination; minification is actually faster than not using it)

- a simple plugin system for use cases like other compiled frameworks like Vue or Svelte, or whatever else you might want in a build pipeline

1 comments

On the downside, it will put all the code into one giant script that has to be downloaded upfront.

While a website that loads scripts per page will only load the scripts that are needed on the current page.

Unless your site is made of 4 files/modules, you simply must bundle. ESM will download the files in series, as each dependency is discovered. Then compression doesn’t work as well as it will be per-file. Then of course you can’t tree-shake dependencies from npm, so good luck downloading the whole of lodash on your client.

In short you lose the advantages of only download what you need pretty quickly.

> good luck downloading the whole of lodash on your client

I never felt the need to use loadash. But even if a site would do that, it does not seem like a big issue. It is 71k. A Twitter profile page is over 5MB. 70 times the size of that loadash library. An appartment page on AirBnB is over 9MB. An Instagram profile page is over 9MB too.

ESBuild does support code splitting, in case you weren’t aware.